删除鼠标单击并为简单的Javascript添加边框

时间:2019-10-31 09:57:59

标签: javascript mouseover

致意,在此先感谢您的帮助。我的第一个javascript技巧。只是尝试在滑块周围添加2em黑色边框,然后将鼠标悬停在滑块上时移开鼠标指针(我不希望提供图片中的链接)。

链接为:www.bakashana.org/test-slider

这是完整的代码:

<html>
<head>
<script language="JavaScript1.1">
<!--

var slideimages=new Array()
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}
//-->
</script>

</head>
<body>
<center><a href="javascript:slideshowimages()"><img src="https://secureservercdn.net/198.71.233.163/4b5.320.myftpupload.com/wp-content/uploads/2019/09/cropped-girls-jump-compressor-400x300_c.jpg" name="slide" border="2em" width=400 height=300></a></center>
<script>
<!--

//configure the paths of the images, plus corresponding target links
slideshowimages("https://secureservercdn.net/198.71.233.163/4b5.320.myftpupload.com/wp-content/uploads/2019/09/cropped-girls-jump-compressor-400x300_c.jpg","https://secureservercdn.net/198.71.233.163/4b5.320.myftpupload.com/wp-content/uploads/2019/09/All-the-ladies-compressor-400x300_c.jpg","https://secureservercdn.net/198.71.233.163/4b5.320.myftpupload.com/wp-content/uploads/2019/09/highcompress-banner20-400x300_c.jpg","https://secureservercdn.net/198.71.233.163/4b5.320.myftpupload.com/wp-content/uploads/2019/09/banner10-1-compressor-400x300_c.jpg","https://secureservercdn.net/198.71.233.163/4b5.320.myftpupload.com/wp-content/uploads/2019/09/cropped-banner-testing-compressor-400x300_c.jpg")

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=2000

var whichimage=0
function slideit(){
if (!document.images)
return
document.images.slide.src=slideimages[whichimage].src
whichlink=whichimage
if (whichimage<slideimages.length-1)
whichimage++
else
whichimage=0
setTimeout("slideit()",slideshowspeed)
}
slideit()

//-->
</script>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

好吧,正如您在评论中提到的那样。使用简单的CSS删除游标:通过向滑块添加cursor:none属性,并使用伪类:hover来检查游标是否悬停在给定的div上,然后将border属性应用于该游标鼠标点击这样的滑块,但是为此我们需要使用jquery,我在下面的代码段工作示例中添加了jquery。

	var event = $("#yourSlider").click(function(e) {
    e.stopPropagation();
    e.preventDefault();
    e.stopImmediatePropagation();
    return false;
});

// disable right click
$("#yourSlider").bind('contextmenu', function(e) {
    e.stopPropagation();
    e.preventDefault();
    e.stopImmediatePropagation();
    return false;
});
#yourSlider{
    background:orange;
    width:400px;
    height:300px;
    cursor:none;
}
#yourSlider:hover{
  border:1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="yourSlider"></div>

答案 1 :(得分:0)

谢谢大家的帮助!我尝试了上述解决方案,但无法使其正常工作(滚动时继续看到鼠标的手)。我找到了最简单的解决方案,我想将其发布给其他人查看。

<style>
#yourSlider{
    width:400px !important;
    height:300px !important;
    border:.2em solid black;
    pointer-events:none !important;

}
</style>

'pointer-events:none!important'负责解决滚动问题(没有添加!important则不起作用),border负责边界问题。

再次感谢所有贡献者!