将切换和单击功能与 JQuery 相结合
我的网站上有一个幻灯片库。我正在使用 JQuery 插件中的一个脚本,当我单击锚点时,它会执行一些功能。我想要做的是看看是否可以使暂停按钮在单击时更改为悬停状态,然后如果再次单击则更改回正常状态。
我尝试这样做,只是说如果 img.src == 正常状态,然后在单击时将其更改为悬停状态。当然不起作用,因为当你将鼠标悬停在它上面时,它不再处于正常状态。希望这是有道理的。这是我的代码:
<a id="galleryPause" href="#">
<img src="images/galleryPause.jpg" onmouseover="this.src='images/galleryPauseHover.jpg'" onmouseout="this.src='images/galleryPause.jpg'" style="margin-left:-4px;" />
</a>
我基本上想保留现有的悬停功能并向其添加单击功能,将默认图像更改为悬停状态并返回。这是为了让用户知道图库已暂停。感谢您对此的任何帮助!
更新: 这是我正在使用的插件的代码。有没有办法可以劫持这段代码以使其执行我想要的操作?
插件脚本链接: http://gsgd.co.uk/sandbox /jquery/easing/jquery.easing.1.3.js
我页面的 ...
中的代码:
<script type="text/javascript">
var autoPlayTime=5000;
autoPlayTimer = setInterval( autoPlay, autoPlayTime);
function autoPlay(){
Slidebox('next');
}
$('#bannerWrapper .thumbs .next').click(function () {
Slidebox('next','next');
});
$('#bannerWrapper .thumbs .previous').click(function () {
Slidebox('previous','next');
});
});
//slide page to id
function Slidebox(slideTo,autoPlay){
var animSpeed=1000; //animation speed
var easeType='easeInOutExpo'; //easing type
var sliderWidth=$('#bannerWrapper').width();
var leftPosition=$('#bannerWrapper .container').css("left").replace("px", "");
$("#bannerWrapper .content").each(function (i) {
totalContent=i*sliderWidth;
$('#bannerWrapper .container').css("width",totalContent+sliderWidth);
});
if( !$("#bannerWrapper .container").is(":animated")){
if(slideTo=='next'){ //next
if(autoPlay=='stop'){
clearInterval(autoPlayTimer);
}
if(leftPosition==-totalContent){
$('#bannerWrapper .container').animate({left: 0}, animSpeed, easeType); //reset
} else {
$('#bannerWrapper .container').animate({left: '-='+sliderWidth}, animSpeed, easeType); //next
}
} else if(slideTo=='previous'){ //previous
if(autoPlay=='stop'){
clearInterval(autoPlayTimer);
}
if(leftPosition=='0'){
$('#bannerWrapper .container').animate({left: '-'+totalContent}, animSpeed, easeType); //reset
} else {
$('#bannerWrapper .container').animate({left: '+='+sliderWidth}, animSpeed, easeType); //previous
}
} else {
var slide2=(slideTo-1)*sliderWidth;
if(leftPosition!=-slide2){
clearInterval(autoPlayTimer);
$('#bannerWrapper .container').animate({left: -slide2}, animSpeed, easeType); //go to number
}
}
}
}
</script>
I have a slideshow gallery on my site. There's a script from a JQuery plugin that i'm using that performs some functions when i click on the anchor. What i am wanting to do is see if i can make the pause button change to the hover state when it is clicked and then if it is clicked again change back to the normal state.
I tried doing this by just saying if the img.src == the normal state then change it to the hover state when clicked. The of course didn't work because when you hover over it, it is no longer on the normal state. Hope that makes sense. here's my code:
<a id="galleryPause" href="#">
<img src="images/galleryPause.jpg" onmouseover="this.src='images/galleryPauseHover.jpg'" onmouseout="this.src='images/galleryPause.jpg'" style="margin-left:-4px;" />
</a>
I basically want to keep the existing hover functionality and add a click functionality to it that changes the default image to the hover state and back. This is so that the user knows that the gallery is paused. Thanks for any help with this!
UPDATE:
This is the code for the plugin i am using. Is there a way i can hijack this code to get it to do what i'm wanting?
Plugin script link: http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js
Code in the <head>...</head>
of my page:
<script type="text/javascript">
var autoPlayTime=5000;
autoPlayTimer = setInterval( autoPlay, autoPlayTime);
function autoPlay(){
Slidebox('next');
}
$('#bannerWrapper .thumbs .next').click(function () {
Slidebox('next','next');
});
$('#bannerWrapper .thumbs .previous').click(function () {
Slidebox('previous','next');
});
});
//slide page to id
function Slidebox(slideTo,autoPlay){
var animSpeed=1000; //animation speed
var easeType='easeInOutExpo'; //easing type
var sliderWidth=$('#bannerWrapper').width();
var leftPosition=$('#bannerWrapper .container').css("left").replace("px", "");
$("#bannerWrapper .content").each(function (i) {
totalContent=i*sliderWidth;
$('#bannerWrapper .container').css("width",totalContent+sliderWidth);
});
if( !$("#bannerWrapper .container").is(":animated")){
if(slideTo=='next'){ //next
if(autoPlay=='stop'){
clearInterval(autoPlayTimer);
}
if(leftPosition==-totalContent){
$('#bannerWrapper .container').animate({left: 0}, animSpeed, easeType); //reset
} else {
$('#bannerWrapper .container').animate({left: '-='+sliderWidth}, animSpeed, easeType); //next
}
} else if(slideTo=='previous'){ //previous
if(autoPlay=='stop'){
clearInterval(autoPlayTimer);
}
if(leftPosition=='0'){
$('#bannerWrapper .container').animate({left: '-'+totalContent}, animSpeed, easeType); //reset
} else {
$('#bannerWrapper .container').animate({left: '+='+sliderWidth}, animSpeed, easeType); //previous
}
} else {
var slide2=(slideTo-1)*sliderWidth;
if(leftPosition!=-slide2){
clearInterval(autoPlayTimer);
$('#bannerWrapper .container').animate({left: -slide2}, animSpeed, easeType); //go to number
}
}
}
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在代码中跟踪单独的“被单击”状态,则可以使用它来确定单击状态,而不是尝试劫持悬停状态。然后,当鼠标悬停时,您可以检查图库是否已被单击。如果是这样,请绕过正常的悬停事件,直到将来发生单击。因此单击状态将暂停/恢复幻灯片放映。
If you track a separate "is clicked" state in your code, you can use that to determine the click status, rather than trying to hijack the hover state status. Then when hovering, you can check if the gallery has been clicked. If so, bypass the normal hover event, until a future click occurs. So the click state would pause / resume the slideshow.