从另一个页面链接到某个引导程序转盘幻灯片
Linking to a certain bootstrap carousel slide from another page
我有两个.html页面:page1.html和page2.html
在page1.html中,我有一个转盘
<!-- First -->
<div class="item">
<div class="container-fluid">
<div class="row">
<h2 class="carousel-text">Item 1</h2>
</div>
</div>
</div>
<!-- Second -->
<div class="item">
<div class="container-fluid">
<div class="row">
<h2 class="carousel-text">Item 2</h2>
</div>
</div>
</div>
<!-- Third -->
<div class="item">
<div class="container-fluid">
<div class="row">
<h2 class="carousel-text">Item 3</h2>
</div>
</div>
</div>
(这是最重要的部分)
在page2.html中,我有一个链接:
<a href="page1.html">Click me to go to page 3!</a>
我该向链接和旋转木马添加什么,使其正常工作?我找到了这个答案,但不知道如何实现它。
这是您的链接中的代码,我添加了注释来解释它的作用。
function getSlideParameter(key) {
/*I'm not sure why would anyone choose a key with these special characters but,
* but if they do, following RegEx will replace those special characters
*/
key = key.replace(/[*+?^$.'[']{}()|'''/]/g, "''$&"); // escape RegEx meta chars
//searches the URL for occurrence of &key=some number, in case key is 'slide' it's searching for &slide=some number
var match = location.search.match(new RegExp("[?&]" + key + "=([^&]+)(&|$)"));
//replaces any '+' with single space
var slide = match && decodeURIComponent(match[1].replace(/'+/g, " "));
//checking if 'slide' is an integer and not float and that 'slide' is not a string
if (Math.floor(slide) == slide && $.isNumeric(slide))
return parseInt(slide);
else
return 0;//if 'slide' parameter is not present or doesn't have correct values load 0th slide
}
//finally load a particular slide using qs() function
$('#myCarousel').carousel(getSlideParameter('slide'));
此函数只是试图查找名为"slide"的URL查询参数的值。
所以如果当前url是http://stackoverflow.com?hello&slide=2
,那么getSlideParameter('slide')
会给我们2
。
这段代码将添加到您的转盘幻灯片所在的页面,在您的情况下是第1页。
将其添加到页面底部或使用jQuery的ready()函数。
<!-- First -->
<div class="item">
<div class="container-fluid">
<div class="row">
<h2 class="carousel-text">Item 1</h2>
</div>
</div>
</div>
<!-- Second -->
<div class="item">
<div class="container-fluid">
<div class="row">
<h2 class="carousel-text">Item 2</h2>
</div>
</div>
</div>
<!-- Third -->
<div class="item">
<div class="container-fluid">
<div class="row">
<h2 class="carousel-text">Item 3</h2>
</div>
</div>
</div>
<script>
//preparation of carousel
</script>
<!-- new script for loading a particular slide -->
<script>
(function () {
function getSlideParameter(key) {
key = key.replace(/[*+?^$.'[']{}()|'''/]/g, "''$&"); // escape RegEx meta chars
var match = location.search.match(new RegExp("[?&]" + key + "=([^&]+)(&|$)"));
var slide = match && decodeURIComponent(match[1].replace(/'+/g, " "));
if (Math.floor(slide) == slide && $.isNumeric(slide))
return parseInt(slide);
else
return 0;//if 'slide' parameter is not present or doesn't have correct values load 0th slide
}
$('#myCarousel').carousel(getSlideParameter('slide'));
})();
</script>
现在,我们终于可以在第2页中给出特定幻灯片的链接,如下
<a href="page1.html?slide=1">Slide 1!</a>
<a href="page1.html?slide=3">Slide 3!</a>
这就是它的全部。
相关文章:
- Html引导程序警报自动关闭困难
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- Twitter引导程序Typeahead-Id&标签
- 引导程序崩溃一次只能看到一个
- 引导程序/基础堆叠行/列
- 轮播标题在更改幻灯片引导程序时不会消失
- twitter引导程序转盘直接链接到特定幻灯片
- 引导程序3转盘-随机选择下一张幻灯片
- 需要使用引导程序的列表组制作“幻灯片”
- 如何将引导程序的轮播过渡从幻灯片更改为淡入淡出
- 引导程序 3 轮播上的计数器未显示正确数量的幻灯片
- 从另一个页面链接到某个引导程序转盘幻灯片
- 奇怪的引导程序旋转木马问题.第一张幻灯片最初没有加载
- 从引导程序旋转木马中的特定幻灯片开始
- 引导程序转盘在更改幻灯片时调整图像大小
- 使用twitter引导程序显示左侧菜单的页面幻灯片
- 如何在引导程序3转盘yii2中设置活动幻灯片
- 一个页面中不同引导程序转盘幻灯片的不同链接
- 幻灯片菜单与引导程序相结合
- 如何瞄准引导程序转盘's的活动幻灯片