我正试图将按钮右侧的面板向左滑动。这是我的css:
的style.css:
.pToolContainer {
position : absolute;
right: 0;
}
.btn-pTool{
//display:block;
position:absolute;
right: 0;
margin:0;
padding:0;
background-image: url(slide_button.png);
background-repeat:no-repeat;
}
.btn-pToolName{
text-align: center;
width: 26px;
height: 190px;
display: block;
color: #fff;
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 1em;
line-height: 32px;
}
.pToolSlidePanel{
min-height: 185px;
min-width: 185px; /*WIDTH OF HIDDEN SLIDE PANEL*/
display: none; /*THE ELEMENT WILL NOT BE DISPLAYED*/
border-right-width: 2px; /*ADDS RIGHT BORDER OF 2PX*/
border-left-width: 2px; /*ADDS LEFT BORDER OF 2PK*/
border-right-style: solid; /*MAKES RIGHT BORDER SOLID*/
border-left-style: solid; /*MAKES LEFT BORDER SOLID*/
border-right-color: #626262; /*RIGHT BORDER COLOR*/
border-left-color: #626262; /*LEFT BORDER COLOR*/
background-color: #949494; /*SLIDE PANEL BACKGROUND COLOR*/
border-bottom-width: 2px; /*ADDS BOTTOM BORDER OF 2PX*/
border-bottom-style: solid; /*MAKES BOTTOM BORDER SOLID*/
border-bottom-color: #626262;
border-top-width: 2px; /*ADDS BOTTOM BORDER OF 2PX*/
border-top-style: solid; /*MAKES BOTTOM BORDER SOLID*/
border-top-color: #626262; /*BOTTOM BORDER COLOR*/
opacity: .8; /*SETS SLIDE PANEL BACKGROUND'S OPACITY TO 80%*/
margin: auto; /*CENTERS OUR SLIDE PANEL*/
position: fixed;
//bottom: 50px;
overflow:hidden;
}
的test.html:
<div class="pToolContainer">
<span class="btn-pTool">
<a class="btn-pToolName" href="#"></a>
</span>
<div class="pToolSlidePanel"></div>
</div>
我已尝试过以下jquery语句,但它似乎不起作用:
$(pToolSlidePanel).animate({width:'toggle'},2000);
其中pToolSlidePanel是我的javascript文件中创建的HTMLElement:
var pToolSlidePanel = document.createElement(“div”);
我也尝试了以下教程http://www.learningjquery.com/2009/02/slide-elements-in-different-directions,但我一直收到一条错误,指出HTMLElement没有css方法
答案 0 :(得分:2)
$(function() {
var iXS = 3, $slider = $('.panel-inner'), liW = $slider.find('li:first').width(), liFW = parseInt(liW * $slider.find('li').length);
$slider.css('width', liFW + 'px');
$('.button a').click(function() {
var left = (this.id == 'right') ? parseInt($slider.css('left').toString().replace('-', '')) : parseInt($slider.css('left'));
var side = (this.id == 'right') ? (((left + (liW * iXS)) == liFW) ? 0 : -(left + liW)) : ((left < 0) ? -(parseInt(left.toString().replace('-', '')) - liW) : 0);
rotate(side);
return false;
});
var rotate = function(leftY) {
$slider.stop(true, true).animate({
left : leftY
}, 500);
}
});
查看完整代码,查看演示示例的源代码。
答案 1 :(得分:1)
尝试这个
$(".pToolSlidePanel").animate({width:'toggle'},2000);
对于Class pToolSlidePanel ,请使用$(".pToolSlidePanel")
和例如:id pToolSlidePanel 使用$("#pToolSlidePanel")
答案 2 :(得分:0)
修改:在此处尝试此配置 http://jsfiddle.net/TQZh5/50/
我删除了一些CSS以使其更容易,但重新添加它应该是微不足道的。
$(pToolSlidePanel).animate({width:'toggle'},2000);
应该是
$('.pToolSlidePanel').animate({width:'toggle'},2000)
;
另外,你对动画动作的约束是什么? jQuery是否包含在ready()函数中,因此它知道DOM已完全加载?
答案 3 :(得分:0)
想要将元素从位置A(右)滑动到B(左)?
HTML:
<div class="pToolContainer">
<div class="pToolSlidePanel">
</div>
</div>
CSS:
.pToolContainer {
width:400px;
height:100px;
background-color:#ccc;
position:relative;
}
.pToolSlidePanel
{
position:absolute;
right:0;
top:0;
width:100px;
height:100px;
background-color:#ffcc33;
}
Javascript(jQuery):
$('.pToolSlidePanel').animate({
left: '-=200'
}, 2000);