需要按钮显示/隐藏图像旋转 href 添加到 javascript 代码中
Need button for show/hide image rotation href added to javascript code
我有以下脚本,当您单击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
相关文章:
- 在类似Facebook的社交墙中添加href
- 如果window.location.href.indexOf('player=1')添加样式
- 添加基于子<a>href
- 如何在标记href中添加按钮
- 将标记添加到您的 href
- 将href链接添加到通过js鼠标悬停显示的图像
- CSS 在悬停时使图像变暗 - 在其周围添加一个 href
- 以编程方式添加 href 时缺少铬锚点下划线
- 删除和添加href中的节点
- 如何添加href"关闭“;链接到Fancybox模式窗口
- 如何在具有相同 src 的图像上自动添加 href
- 如何通过jquery在(a)中添加(href)
- 使用 JavaScript 追加添加 href
- 在事件单击函数中添加href url
- 添加href锚标记不工作在Internet explorer
- 每当Javascript中出现正则表达式时,向文档的内容添加href
- 文档.Write(添加href的语法问题)
- 如何在Gojs中的节点内部添加href
- 如何使用Angular挂接单击链接,并在单击完成之前添加href
- Highchart:在堆叠条形图的每一段添加href