首页 > 其他 > 详细

鼠标悬浮动态加载图片

时间:2020-05-06 10:13:52      阅读:66      评论:0      收藏:0      [点我收藏+]

效果图:

技术分享图片

 

技术分享图片

1.html 代码

元素块代码

<!-- 动态显示加载图片元素块 -->
<div id="showimgdiv" style="position:absolute;left=0;top=0;display:none;" >
    <input id="showimg" type="image" style="max-width: 800px;max-height: 800px;"/>
</div

图片悬浮事件代码

<-- 图片移入移出事件 -->
<
img class="imageMouse" onMousemove="show(this)" onmouseout="hide(this)" src="http://p9.qhimg.com/bdm/480_296_0/t013a4ed4683039d101.jpg">

2.script 的function代码

function show(element){
    // 以下代码功能与未注释一样,只是方法不同
    // document.all.showimg.src = element.src;
    // document.all.showimgdiv.style.left = "200px";
    // document.all.showimgdiv.style.top = "10px";
    $("#showimg").attr("src",element.src);
    //显示动态加载模块de内容
    var showDiv=$("#showimgdiv");
    //showDiv.css(‘position‘,‘absolute‘);
    //根据div的 DOM 对象的中间变量element动态定位
       showDiv.css(‘left‘,parseInt(element.x)+30+parseInt($(document).scrollLeft())+"px");
    if(parseInt(element.y)-parseInt(showDiv.height())>=0){
        showDiv.css(‘top‘,parseInt(element.y)+parseInt($(document).scrollTop())-parseInt(showDiv.height())+"px");
    }else{
        var divtop = parseInt(showDiv.height())-parseInt(element.y);
        showDiv.css(‘top‘,parseInt(element.y)+parseInt($(document).scrollTop())-parseInt(showDiv.height())+parseInt(divtop)+"px");
    }
    document.all.showimgdiv.style.display = "";
}
function hide(){
    document.all.showimgdiv.style.left = 0;
    document.all.showimgdiv.style.top = 0;
    document.all.showimgdiv.style.display = "none";
}

鼠标悬浮动态加载图片

原文:https://www.cnblogs.com/mjtabu/p/12834456.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!