Javascript 使用引导转盘按钮滚动到某个位置
我有一个转盘按钮,可以在图像中前后滚动 我的问题是旋转木马的href是“#phonedemo”,因为这是存储图像的地方。滚动条也会移动到该特定位置 我遇到的问题是,旋转木马包含在另一个图像中,我希望滚动到该图像的顶部 更改为href=“#contentfeadtures”会将其移动到正确的位置,但不再更改旋转木马图像 这是htmlJavascript 使用引导转盘按钮滚动到某个位置,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,我有一个转盘按钮,可以在图像中前后滚动 我的问题是旋转木马的href是“#phonedemo”,因为这是存储图像的地方。滚动条也会移动到该特定位置 我遇到的问题是,旋转木马包含在另一个图像中,我希望滚动到该图像的顶部 更改为href=“#contentfeadtures”会将其移动到正确的位置,但不再更改旋转木马图像 这是html <div id="contentFeadtures" class="row"> <h1 class="col-White">Featu
<div id="contentFeadtures" class="row">
<h1 class="col-White">Features</h1>
<div class="row">
<div id="phonedemo" class="carousel slide" data-ride="carousel">
<div class="phonedemoHouseing">
<div class="phonedemoContainer">
<div class="carousel-inner center-block" role="listbox">
<div class="item active">
<img src="images/carousel-1-ca.jpg" class="img-responsive">
</div>
<div class="item">
<img src="images/carousel-1-.jpg" class="img-responsive">
</div>
<div class="item">
<img src="images/carousel-1-.jpg" class="img-responsive">
</div>
<div class="item">
<img src="images/carousel-1-.jpg" class="img-responsive">
</div>
<div class="item">
<img src="images/carousel-1-.jpg" class="img-responsive">
</div>
</div>
</div>
</div>
<a class="left carousel-control" href="#phonedemo" role="button" data-slide="prev">
<img src="images/back.png" class="img-responsive">
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#phonedemo" role="button" data-slide="next">
<img src="images/forward.png" class="img-responsive">
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
因此,我不希望按钮滚动到#phonedemo,而是希望它转到#contentfeadtures,但保留移动页面功能。如果使用jQuery,则捕获锚定标记的单击事件并滚动到顶部。contentfeadtures可能会解决此问题
$('.carousel-control').on('click', function() {
$('html, body').scrollTo('#contentfeadtures',{duration:'slow', offsetTop : '0'});
});
您可以尝试的另一种解决方案
将href替换为指向旋转木马的数据目标属性
data-target="#phonedemo"
Lokesh Yadav关于用数据目标替换href的建议解决了我的问题。当我点击旋转木马控件时,幻灯片爬到了顶部,隐藏在菜单后面,带有“粘贴顶部”。现在它保持静止。我是巴西人,我需要翻译这篇评论。这是我在最后一分钟从别人那里抢来的一个项目,所以我不确定我要看什么。我能找到的唯一滚动jquery是//滚动到$('.navbar').localScroll(200,{easing:'elasout'})$('section#objective,section#creationdesign,section#features,section#results')。localScroll(2000,{easing:'elasout');不幸的是,它仍然滚动到phonedemo的href而不是内容。请将href替换为数据目标属性,参考您的旋转木马:data target=“#phonedemo”您应该将其作为对问题的评论而不是答案发布。
data-target="#phonedemo"