javascript-Colorbox放置在另一个元素的顶部
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-Colorbox放置在另一个元素的顶部,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2707字,纯文字阅读大概需要4分钟。
内容图文
我对colorbox的定位有很大的疑问.对于我的目的,官方网站http://www.jacklmoore.com/colorbox/上描述的方法还不够.关键是我要打开颜色框的按钮,并且需要将其定位在“按钮上方”(按钮的高度为50px,颜色框的高度约为700px,所以我需要将其居中放置在按钮上方(例如按钮顶部300px ).
我已经尝试过使用jquery在onOpen和colorbox中的onLoad函数中进行基本的重新定位,例如:
onOpen:function() {
$('#colorbox').removeAttr('top');
$('#colorbox').css('top','200px');
},
它可以工作,但是颜色框设置会在onOpen或onLoad之后立即自动覆盖这些设置,并且颜色框会再次位于视口的中心.
所以我基本上是在寻求帮助,例如顶部,左侧等颜色框定位设置根本不足以定位在按钮元素的顶部.
提前致谢!
编辑:完整代码如下
$(".reserve_").live('click',function() {
var loadUrl = $(this).attr("href");
$.colorbox({
innerWidth:660,
innerHeight:720,
returnFocus: true,
overlayClose: true,
fixed: false,
iframe: true,
href: loadUrl,
opacity: 0.6,
reposition: true,
onOpen:function() {
$('#colorbox').removeAttr('top');//test
$('#colorbox').css('top','200px');//test
},
onl oad: function() {
$('#colorbox').removeAttr('top');//test
$('#colorbox').css('top','200px');//test
},
onClosed:function() {
}
});
return false;
});
编辑2:jsfiddle上的链接:http://jsfiddle.net/zS8J8/8/(对不起CSS和HTML中的凌乱代码)
解决方法:
jsfiddle很有帮助,我能够使用与您相同的代码并使它工作.
这已在Win 7上的firefox 20,chrome 26,IE 9中进行了测试.使用HTML在IE中“ Open Colorbox”链接不可见,但是如果将鼠标移至该区域,则会看到光标变化并且如果单击,Colorbox将在正确的位置打开.
这是HTML,我将class =“ rezervuj”更改为id =“ rezervuj”,因为我们是在键入单个元素而不是一堆图像:
<h3 style="margin-bottom: 300px;">TOP OF THE PAGE</h3>
<div class="unitKontejner">
<div style="float:right;">
<a id="rezervuj" href="http://www.imgur.com">
<div class="reserveIt">
<div class="reserveIt-content">
open colorbox ?
</div>
</div>
</a>
</div>
</div>
这是您可以放在开头的脚本:
<script>
$(document).ready(function(){
// I removed the options that were set to the default.
// The top and left can be left out or set to a default,
// I used them as a test to see the difference when the event hook is used.
$("#rezervuj").colorbox({
iframe:true,
innerWidth:660,
innerHeight:720,
opacity: 0.6,
top: 0,
left: 0
});
// Use the "cbox_complete" event hook.
// It allows the colorbox div to be positioned after it opens,
// but before the content is loaded.
$(document).bind('cbox_complete', function(){
// Grab the position of the button,
// colorbox can be positioned relative to it.
var pos = $(rezervuj).position();
//console.log(pos);
// Set the position of the colorbox div
// You can add to or subtract from the pos values
// Example: top: (pos.top + 20) + "px"
$("#colorbox").css({
position: "absolute",
top: pos.top + "px",
left: pos.left + "px"
}).show();
});
});
</script>
内容总结
以上是互联网集市为您收集整理的javascript-Colorbox放置在另一个元素的顶部全部内容,希望文章能够帮你解决javascript-Colorbox放置在另一个元素的顶部所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。