需要按钮显示/隐藏图像旋转 href 添加到 javascript 代码中

Need button for show/hide image rotation href added to javascript code

本文关键字:添加 href javascript 代码 旋转 图像 按钮 显示 隐藏      更新时间:2023-09-26

我有以下脚本,当您单击div 中的图像时,它会在新窗口中打开相应的 href 链接。同时,在父页面上单击的div 将隐藏,并显示下一个div。

还有一个"下一步"按钮,因此为了在不单击图像的情况下前进到下一个div。这个"下一步"按钮不会在当前div 上打开相应的 href。它只是跳到下一个div。

这一切都完美运行,但是我现在正在尝试添加一个按钮,单击该按钮会将您带到可见div 的 href 位置。

这有意义吗?

下面是一个 JSFiddle 演示:http://jsfiddle.net/QTyRq/

这是代码...

<div id="container">
    <div class="imgrotation"><a href="http://google.com" target="_blank"><img src="abc.jpg" width="100" height="100" border="0" /></a></div>
    <div class="imgrotation"><a href="http://yahoo.com" target="_blank"><img src="def.jpg" width="200" height="200" border="0" /></a></div>
    <div class="imgrotation"><a href="http://msn.com" target="_blank"><img src="ghi.jpg" width="300" height="300" border="0" /></a></div>
    <div class="imgrotation"><a href="http://bing.com" target="_blank"><img src="jkl.jpg" width="400" height="400" border="0" /></a></div>
</div>
<button id="nextimg">Next Image</button>
<!--This is what I need added to JS -->
<button id="gotourl">Visit Site</button>

Jquery:

var alldoneURL = 'next-image-group.html'; //final click
function next(event, duration) {
    duration = duration || 900; // default value
    var that = $('.imgrotation:visible');
    if (that.next('.imgrotation').length) {
        that.fadeOut(duration, function() {
            that.next('.imgrotation').fadeIn(duration);
        });
    } else {
        window.location.href = alldoneURL;
    }
    return false;
}
$('.imgrotation').not(':first').hide();
$('.imgrotation a').click(
function(e) {
    e.preventDefault();
    var newWin = window.open(this.href), //(this.href, 'newWindow') to load all clicks in one window.open
        duration = 900;
    next(e, duration);
});
$('#nextimg').click(next);

添加这个jquery也可以工作

$('#gotourl').on('click',function(){
      window.open($(".imgrotation:visible a").prop('href'));
});

http://jsfiddle.net/QTyRq/3/

function$('#gotourl').on('click',function(){
    window.open($(".imgrotation:visible a").prop('href'));
    $('#nextimg').trigger('click');
});

更新了两者的 JSFIDDLE