简体   繁体   English

Stellar.js与位置问题

[英]Stellar.js issue with position

I'm trying to use Stellar.js to do a parallax effect, but the data-stellar-ratio="" tag is getting my elements out of position. 我正在尝试使用Stellar.js来做视差效果,但data-stellar-ratio =“”标签让我的元素不合适。 I have this codes: 我有这个代码:

<div class="slider" id="yours" data-slide="3" data-stellar-background-ratio="0.5">
<div class="container">
<div class="outer-ring" data-stellar-ratio="0.6">
<div class="inner-ring" data-stellar-ratio="-0.6" data-stellar-vertical-offset="0">
<div class="core" data-stellar-ratio="-0.3" data-stellar-vertical-offset="0"></div></div></div></div></div>

with these css: 用这些css:

.outer-ring {
    width: 635px;
    height: 635px;
    background: url(../img/conheca/wheel-1.png) no-repeat;
    position: absolute;
    top: 50%;
    margin-top: -317px;
    left: 50%;
    margin-left: -317px;
}

.inner-ring {
    width: 478px;
    height: 478px;
    background: url(../img/conheca/wheel-2.png) no-repeat;
    position: relative;
    margin: 0px auto;
}

.core {
    width: 360px;
    height: 360px;
    background: url(../img/conheca/wheel-3.png) no-repeat;
    position: relative;
    margin: 0px auto;
}

When Stellar "data-ratio" is not in the tags, it fits well, but when i put this parameter it changes the "top" of .inner-ring and .core. 当Stellar“数据比率”不在标签中时,它很适合,但是当我输入此参数时,它会改变.inner-ring和.core的“顶部”。

I had an issue like this with horizontal positioning, the .container div has "margin: 0 auto" and children elements was getting off the div while it have "position: relative", but i chopped off the "margin" piece of code in the Stellar script and it worked. 我有一个像水平定位这样的问题,.container div有“margin:0 auto”和子元素离开div而它有“position:relative”,但我切掉了“margin”代码片段Stellar脚本,它的工作原理。

Sorry if i was a little confuse, but this thing is driving me insane, since the tutorial i've been following (http://webdesign.tutsplus.com/tutorials/complete-websites/create-a-parallax-scrolling-website-using-stellar-js/) doesn't mention this and neither the Stellar.js site. 对不起,如果我有点迷惑,但这件事让我疯了,因为我一直关注的教程(http://webdesign.tutsplus.com/tutorials/complete-websites/create-a-parallax-scrolling-website -using-stellar-js /)没有提到这个,也没有提到Stellar.js网站。 Thanks. 谢谢。

Make sure that all parent elements has position: relative ? 确保所有父元素都有position: relative

Also, you can set offset when calling the script, and if you only going to work with vertical scrolling you can simply shut off the horizontal scrolling: 此外,您可以在调用脚本时设置偏移量,如果您只使用垂直滚动,则可以简单地关闭水平滚动:

  $(window).stellar({
    horizontalScrolling: false,
    verticalOffset: 0,
    horizontalOffset: 0
  });

Good luck! 祝好运!

Try this tutorial: http://coding.smashingmagazine.com/2011/07/12/behind-the-scenes-of-nike-better-world/ 试试这个教程: http//coding.smashingmagazine.com/2011/07/12/behind-the-scenes-of-nike-better-world/

I find stellar.js unpolished yet. 我发现stellar.js尚未完成。

I answered a similar issue here - stellar.js background image position issue 我在这里回答了类似的问题 - stellar.js背景图片位置问题

Basically its because you have horizontal scrolling set to 'true' in the stellar function. 基本上是因为你在恒星函数中将水平滚动设置为'true'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM