蓝戒博客

  • 首页
  • 研发说
  • 架构论
  • 效能录
  • AI谈
  • 随笔集
智构苍穹
融合 AI、架构与工程实践,沉淀方法论,构建可持续的技术价值。
  1. 首页
  2. 研发说
  3. 正文

js鼠标滑到图片上显示渐变弹出大图

2013年10月11日 8285点热度 0人点赞 0条评论

js鼠标滑到图片上显示渐变弹出大图

dome示例:

dreamweaver

js代码如下:

[codesyntax lang="php"]

function getViewportHeight() {
if (window.innerHeight!=window.undefined) return window.innerHeight;
if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
if (document.body) return document.body.clientHeight;

return window.undefined;
}
function getViewportWidth() {
if (window.innerWidth!=window.undefined) return window.innerWidth;
if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
if (document.body) return document.body.clientWidth;

return window.undefined;
}

/**
* Gets the real scroll top
*/
function getScrollTop() {
if (self.pageYOffset) // all except Explorer
{
return self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
return document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
return document.body.scrollTop;
}
}
function getScrollLeft() {
if (self.pageXOffset) // all except Explorer
{
return self.pageXOffset;
}
else if (document.documentElement && document.documentElement.scrollLeft)
// Explorer 6 Strict
{
return document.documentElement.scrollLeft;
}
else if (document.body) // all other Explorers
{
return document.body.scrollLeft;
}
}
/*
渐变的弹出图片
使用方法:
将ToolTip.js包含在网页body的结束标签后
调用方法:

<a href="http://www.webzsky.com/source/web_img/dwcs6_01.jpg" target='_blank' onMouseOver="toolTip('<img src=http://www.webzsky.com/source/web_img/dwcs6_02.jpg>')" onMouseOut="toolTip()"><img src='http://www.webzsky.com/source/web_img/dwcs6_01.jpg' border=0 1 title="点击看大图"></a>

必须CSS样式
.trans_msg
{
filter:alpha(opacity=100,enabled=1) revealTrans(duration=.2,transition=1) blendtrans(duration=.2);
}
*/
//--初始化变量--
var rT=true;//允许图像过渡
var bT=true;//允许图像淡入淡出
var tw=150;//提示框宽度
var endaction=false;//结束动画
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 10;
offsetY = 20;
var toolTipSTYLE="";
function initToolTips()
{
tempDiv = document.createElement("div");
tempDiv.id = "toolTipLayer";
tempDiv.style.position = "absolute";
tempDiv.style.display = "none";
document.body.appendChild(tempDiv);
if(ns4||ns6||ie4)
{
if(ns4) toolTipSTYLE = document.toolTipLayer;
else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
if(ns4) document.captureEvents(Event.MOUSEMOVE);
else
{
toolTipSTYLE.visibility = "visible";
toolTipSTYLE.display = "none";
}
document.onmousemove = moveToMouseLoc;
}
}
function toolTip(msg, fg, bg)
{
try {
if(toolTip.arguments.length < 1) // hide
{
if(ns4)
{
toolTipSTYLE.visibility = "hidden";
}
else
{
//--图象过渡,淡出处理--
if (!endaction) {toolTipSTYLE.display = "none";}
if (rT) document.all("msg1").filters[1].Apply();
if (bT) document.all("msg1").filters[2].Apply();
document.all("msg1").filters[0].opacity=0;
if (rT) document.all("msg1").filters[1].Play();
if (bT) document.all("msg1").filters[2].Play();
if (rT){
if (document.all("msg1").filters[1].status==1 || document.all("msg1").filters[1].status==0){
toolTipSTYLE.display = "none";}
}
if (bT){
if (document.all("msg1").filters[2].status==1 || document.all("msg1").filters[2].status==0){
toolTipSTYLE.display = "none";}
}
if (!rT && !bT) toolTipSTYLE.display = "none";
//----------------------
}
}
else // show
{
if(!fg) fg = "#777777";
if(!bg) bg = "#eeeeee";
var content =
'

' +
'

' + msg +
'

';

if(ns4)
{
toolTipSTYLE.document.write(content);
toolTipSTYLE.document.close();
toolTipSTYLE.visibility = "visible";
}
if(ns6)
{
document.getElementById("toolTipLayer").innerHTML = content;
toolTipSTYLE.display='block'
}
if(ie4)
{
document.all("toolTipLayer").innerHTML=content;
toolTipSTYLE.display='block'
//--图象过渡,淡入处理--
var cssopaction=document.all("msg1").filters[0].opacity
document.all("msg1").filters[0].opacity=0;
if (rT) document.all("msg1").filters[1].Apply();
if (bT) document.all("msg1").filters[2].Apply();
document.all("msg1").filters[0].opacity=cssopaction;
if (rT) document.all("msg1").filters[1].Play();
if (bT) document.all("msg1").filters[2].Play();
//----------------------
}
}
} catch(e) {}
}
function moveToMouseLoc(e)
{
var scrollTop = getScrollTop();
var scrollLeft = getScrollLeft();
if(ns4||ns6)
{
x = e.pageX + scrollLeft;
y = e.pageY - scrollTop;
}
else
{
x = event.clientX + scrollLeft;
y = event.clientY;
}

if (x-scrollLeft > getViewportWidth() / 2) {
x = x - document.getElementById("toolTipLayer").offsetWidth - 2 * offsetX;
}

if ((y+document.getElementById("toolTipLayer").offsetHeight+offsetY)>getViewportHeight()) {
y = getViewportHeight()-document.getElementById("toolTipLayer").offsetHeight-offsetY;
}
toolTipSTYLE.left = (x + offsetX)+'px';
toolTipSTYLE.top = (y + offsetY + scrollTop)+'px';
return true;
}
initToolTips();

[/codesyntax]

html代码如下:

<a onmouseover="toolTip('&lt;img src=http://www.webzsky.com/source/web_img/dwcs6_02.jpg&gt;')" onmouseout="toolTip()" href="http://www.webzsky.com/source/web_img/dwcs6_02.jpg" target="_blank"><img title="点击看大图" alt="" src="http://www.webzsky.com/source/web_img/dwcs6_01.jpg" width="240" height="260" align="absmiddle" border="0" /></a>

js下载

标签: javascript 图片特效
最后更新:2025年9月13日

cywcd

我始终相信,技术不仅是解决问题的工具,更是推动思维进化和创造价值的方式。从研发到架构,追求极致效能;在随笔中沉淀思考,于 AI 中对话未来。

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

cywcd

我始终相信,技术不仅是解决问题的工具,更是推动思维进化和创造价值的方式。从研发到架构,追求极致效能;在随笔中沉淀思考,于 AI 中对话未来。

最新 热点 随机
最新 热点 随机
狂揽 32 万 Star,让 AI 智能体帮你“逆向一切”:深度拆解 GitHub 现象级神器 morluto/rea 与 6 大最佳实践 OpenCode 曝 1.4% 用户密钥失窃,揭秘黑客“对抗性蒸馏”黑产! Claude 全面开放 OTel 追踪、Cohere 鲸吞 500 漏洞猎手:AI 智能体彻底告别“黑盒裸奔”! 不用显卡、普通 CPU 140 毫秒出结果!Mistral 突发开源 209M 时序模型 Timestral,横扫三大权威榜单 Meta Muse 被“开源复刻”?深度拆解 5000 星 OpenMuse:架构很香,但这 3 个暗坑必须看清 智谱 GLM-Legal 反超 Claude 与 Kimi:18B 激活参数凭什么啃下最严苛法律评测?
不讲废话的 AI 估值 2 亿美元!全面拆解“系统一”决策模型 Jev:70ms 极速响应与工业级实战白嫖 10 亿 Token 与云端虚拟机!Meta Muse 国内成功注册保姆级指南:手把手教你跳过排队请3天休13天!我用火山引擎 Seed-2.1-pro搓了个《国庆旅行模拟器》小游戏宿敌破天荒联手!OpenAI 与 Anthropic 互相“查水表”,Google 证实 Agent 越狱渗透:AI 正在失控边缘?波及 13.4 万智能体!首个零点击 RCE 漏洞 Plugin4Shell 爆发:你锁定的插件正在偷偷黑掉你的电脑阿里开源 OpenCodeReview:给大模型套上“工程缰绳”的代码审查神器
别再把私人邮箱喂给AI了!解析QQ邮箱Agent Mail:专为智能体打造的“数字工位” vue项目开发的一些总结 高效构建响应式Web:Tailwind CSS原子化实战 效率神器 NotebookLM:构建高质量知识库的完整教程与落地最佳实践 OpenCode:一个真正「为程序员而生」的开源 AI 编程 Agent 谷歌突然放大招:Gemma 4,可能是今年最值得本地部署的开源AI大模型
最近评论
cywcd 发布于 4 周前(09月22日) 《牛来跑酷》游戏链接地址已更新: 1. Gemini 3.7 Flash 版 牛来跑酷: htt...
渔夫 发布于 12 个月前(11月05日) 学到了,感谢博主分享
沙拉小王子 发布于 9 年前(11月30日) 适合vue入门者学习,赞一个
沙拉小王子 发布于 9 年前(11月30日) 适合vue入门者学习,赞一个
cywcd 发布于 10 年前(04月27日) 请参考一下这篇文章http://www.jianshu.com/p/fa4460e75cd8

COPYRIGHT © 2025 蓝戒博客_智构苍穹-专注于大前端领域技术生态. ALL RIGHTS RESERVED.

京ICP备12026697号-2