在类之外的类中定位元素
Positioning elements within Classes outside of class
所以我在这里使用这个演示插件http://tympanus.net/Tutorials/PrettySimpleContentSlider/我试图让右边的动画选项卡(ul id="rotmenu")能够自由浮动,并在其主div类"rotor"之外自由定位,同时仍然保持其功能并在rotor中发挥作用。我试着用div和类的属性在这里和那里做一些简单的更改,但它们或多或少都把事情搞砸了。有什么想法吗?
这是使用jquery_easing1.3和jquery.min.js库的js
<script type="text/javascript">
$(function() {
var current = 1;
var iterate = function(){
var i = parseInt(current+1);
var lis = $('#rotmenu').children('li').size();
}
display($('#rotmenu li:first'));
var slidetime = setInterval(iterate,3000);
$('#rotmenu li').bind('click',function(e){
clearTimeout(slidetime);
display($(this));
e.preventDefault();
});
function display(elem){
var $this = elem;
var repeat = false;
if(current == parseInt($this.index() + 1))
repeat = true;
if(!repeat)
$this.parent().find('li:nth-child('+current+') a').stop(true,true).animate({'marginRight':'-20px'},300,function(){
$(this).animate({'opacity':'0.7'},700);
});
current = parseInt($this.index() + 1);
var elem = $('a',$this);
elem.stop(true,true).animate({'marginRight':'0px','opacity':'1.0'},300);
var info_elem = elem.next();
$('#rot1 .heading').animate({'left':'-420px'}, 500,'easeOutCirc',function(){
$('h1',$(this)).html(info_elem.find('.info_heading').html());
$(this).animate({'left':'0px'},400,'easeInOutQuad');
});
$('#rot1 .description').animate({'bottom':'-270px'},500,'easeOutCirc',function(){
$('p',$(this)).html(info_elem.find('.info_description').html());
$(this).animate({'bottom':'0px'},400,'easeInOutQuad');
})
$('#rot1').prepend(
$('<img/>',{
style : 'opacity:0',
className : 'bg'
}).load(
function(){
$(this).animate({'opacity':'1'},600);
$('#rot1 img:first').next().animate({'opacity':'0'},700,function(){
$(this).remove();
});
}
).attr('src','images/'+info_elem.find('.info_image').html()).attr('width','800').attr('height','300')
);
}
});
</script>
应用jquery的
<body>
<div id="content">
<a class="back" href=""></a>
<div class="rotator">
<ul id="rotmenu">
<li>
<a href="rot1">Portfolio</a>
<div style="display:none;">
<div class="info_image">1.jpg</div>
<div class="info_heading">Our Works</div>
<div class="info_description">
<a href="#" class="more">Read more</a>
</div>
</div>
</li>
<li>
<a href="rot2">Services</a>
<div style="display:none;">
<div class="info_image">2.jpg</div>
<div class="info_heading">We serve</div>
<div class="info_description">
<a href="#" class="more">Read more</a>
</div>
</div>
</li>
<li>
<a href="rot3">Contact</a>
<div style="display:none;">
<div class="info_image">3.jpg</div>
<div class="info_heading">Get in touch</div>
<div class="info_description">
<a href="#" class="more">Read more</a>
</div>
</div>
</li>
<li>
<a href="rot4">Experiments</a>
<div style="display:none;">
<div class="info_image">4.jpg</div>
<div class="info_heading">We do crazy stuff</div>
<div class="info_description">
<a href="#" class="more">Read more</a>
</div>
</div>
</li>
<li>
<a href="rot5">Applications</a>
<div style="display:none;">
<div class="info_image">5.jpg</div>
<div class="info_heading">Working things</div>
<div class="info_description">
<a href="#" class="more">Read more</a>
</div>
</div>
</li>
</ul>
<div id="rot1">
<img src="" width="800" height="300" class="bg" alt=""/>
<div class="heading">
<h1></h1>
</div>
<div class="description">
<p></p>
</div>
</div>
</div>
</div>
如果希望它在其父级(.rotator
)之外可见,则需要将父级的CSS更改为具有overflow: visible
。然后,您可以将#rotmenu
放置在任何您想要的位置。
#rotmenu {
position: absolute;
top: 300px;
left: 100px;
z-index: 10;
}
.rotator {
...
overflow:visible;
...
}
此外,为了继续遮罩动画组件,需要将#rot1
设置为overflow:hidden,并使其具有与公共父级(.rotator
)相同的尺寸。
#rot1 {
position: absolute;
overflow: hidden;
height: 100%;
width: 100%;
}
最后,为了防止损坏的图像在DOM中收集(在本例中发生这种情况,因为我们不包括源图像),我在图像插入代码中添加了一个错误处理程序来删除图像。
$('#rot1').prepend(
$('<img/>', {
style: 'opacity:0',
className: 'bg'
}).error(function () {
$(this).remove();
}).load(function () {
$(this).animate({
'opacity': '1'
}, 600);
$('#rot1 img:first').next().animate({
'opacity': '0'
}, 700, function () {
$(this).remove();
});
}).attr('src', 'images/' + info_elem.find('.info_image').html()).attr('width', '800').attr('height', '300'));
jsfiddle
首先,在我看来,你认为因为rotmenu是rotor类的一部分,所以你需要在它之外有rotor类。这不是类的工作方式。如果你想让rotmenu成为这个类的一部分。如果不是这样,那么忽略消息的这一部分。
它的结构是,你的无序列表被一些看不见的div包裹着。我不知道你所说的混乱是什么意思。但是由于它的类,它可能与包装器div的一些css元素有关。
相关文章:
- 在Jquery detachment()和appendTo()之后定位元素
- Selenium无法在浏览器DOM中定位元素
- 固定定位元素在滚动时停止在某个点
- 如何相对于父边框的外边缘定位元素
- 量角器无法定位元素/值
- jQuery动画和定位元素
- 使用ng-click在作用域内定位元素
- 不会转义视口的绝对定位元素
- Z 索引绝对定位元素低于父级,具有 z 索引解决方法
- 不能使用 jQuery 在循环中定位元素的 ID
- 桌面网络工具包(safari / chrome)中具有绝对定位元素的奇怪渲染错误
- 在聚合物重复中定位元素
- 视差.js移动我的 CSS 定位元素
- 怎么能这样定位元素
- 无法使用量角器的绑定定位器定位元素
- Iframe 和绝对定位元素
- 如何使用 jQuery 计算相对定位元素的绝对位置*没有*
- 使用Javascript调整绝对定位元素的大小
- 基于浏览器宽度定位元素时出现问题
- CSS:在IE中使用jquery定位元素