首页 >> js开发 >> jsJS实现页面鼠标点击出现图片特效js大全
jsJS实现页面鼠标点击出现图片特效js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
本文实例为大家分享了js实现页面鼠标点击出现图片,供大家参考,具体内容如下需求:需求:在页面可视区鼠标点击时,鼠标位置出现图片技术:技术:监听器,鼠标坐标获取效果图效果图源码分享:源码分享:图片是动态添加进页面的,所以没有HTML部分。JS
let div = document.createElement("div");
div.id = "mouseImg";
for (let i =0 ; i <3 ;i++){
let img = document.createElement("img");
img.src = "images/timg.gif";
div.appendChild(img);
}
document.body.appendChild(div);
let divImg = document.querySelector("#mouseImg");
document.addEventListener("mousedown",function (e) {
let x = e.pageX;
let y = e.pageY;
divImg.style.left = x + "px" ;
divImg.style.top = y + "px";
let imgs = divImg.children;
for (let i =0 ; i < imgs.length ;i++) {
imgs[i].style.opacity = "1";
setTimeout(function () {
imgs[i].style.opacity = "0";
},2200);
}
});
let div = document.createElement("div");
div.id = "mouseImg";
for (let i =0 ; i <3 ;i++){
let img = document.createElement("img");
img.src = "images/timg.gif";
div.appendChild(img);
}
document.body.appendChild(div);
let divImg = document.querySelector("#mouseImg");
document.addEventListener("mousedown",function (e) {
let x = e.pageX;
let y = e.pageY;
divImg.style.left = x + "px" ;
divImg.style.top = y + "px";
let imgs = divImg.children;
for (let i =0 ; i < imgs.length ;i++) {
imgs[i].style.opacity = "1";
setTimeout(function () {
imgs[i].style.opacity = "0";
},2200);
}
});CSS
body {
background-color: rgba(0, 255, 255, 0.12);
cursor: pointer;
}
#mouseImg {
width: 50px;
height: 50px;
position: absolute;
}
#mouseImg img {
width: 100%;
opacity: 0;
transition: all .9s ease ;
}
#mouseImg img:nth-of-type(2){
transition-delay: .5s;
}
#mouseImg img:nth-of-type(3){
transition-delay: .8s;
}
body {
background-color: rgba(0, 255, 255, 0.12);
cursor: pointer;
}
#mouseImg {
width: 50px;
height: 50px;
position: absolute;
}
#mouseImg img {
width: 100%;
opacity: 0;
transition: all .9s ease ;
}
#mouseImg img:nth-of-type(2){
transition-delay: .5s;
}
#mouseImg img:nth-of-type(3){
transition-delay: .8s;
}
这个案例,也可以做成 图片跟随鼠标移动 上图 !以上就是本文的全部内容,希望对大家的学习有所帮助。
let div = document.createElement("div");
div.id = "mouseImg";
for (let i =0 ; i <3 ;i++){
let img = document.createElement("img");
img.src = "images/timg.gif";
div.appendChild(img);
}
document.body.appendChild(div);
let divImg = document.querySelector("#mouseImg");
document.addEventListener("mousedown",function (e) {
let x = e.pageX;
let y = e.pageY;
divImg.style.left = x + "px" ;
divImg.style.top = y + "px";
let imgs = divImg.children;
for (let i =0 ; i < imgs.length ;i++) {
imgs[i].style.opacity = "1";
setTimeout(function () {
imgs[i].style.opacity = "0";
},2200);
}
});
let div = document.createElement("div");
div.id = "mouseImg";
for (let i =0 ; i <3 ;i++){
let img = document.createElement("img");
img.src = "images/timg.gif";
div.appendChild(img);
}
document.body.appendChild(div);
let divImg = document.querySelector("#mouseImg");
document.addEventListener("mousedown",function (e) {
let x = e.pageX;
let y = e.pageY;
divImg.style.left = x + "px" ;
divImg.style.top = y + "px";
let imgs = divImg.children;
for (let i =0 ; i < imgs.length ;i++) {
imgs[i].style.opacity = "1";
setTimeout(function () {
imgs[i].style.opacity = "0";
},2200);
}
});CSS
body {
background-color: rgba(0, 255, 255, 0.12);
cursor: pointer;
}
#mouseImg {
width: 50px;
height: 50px;
position: absolute;
}
#mouseImg img {
width: 100%;
opacity: 0;
transition: all .9s ease ;
}
#mouseImg img:nth-of-type(2){
transition-delay: .5s;
}
#mouseImg img:nth-of-type(3){
transition-delay: .8s;
}
body {
background-color: rgba(0, 255, 255, 0.12);
cursor: pointer;
}
#mouseImg {
width: 50px;
height: 50px;
position: absolute;
}
#mouseImg img {
width: 100%;
opacity: 0;
transition: all .9s ease ;
}
#mouseImg img:nth-of-type(2){
transition-delay: .5s;
}
#mouseImg img:nth-of-type(3){
transition-delay: .8s;
}
这个案例,也可以做成 图片跟随鼠标移动 上图 !以上就是本文的全部内容,希望对大家的学习有所帮助。