简体   繁体   English

如何将深层链接添加到 HTML5 Up 模板中?

[英]How can I add deep links into an HTML5 Up template?

I am using the following HTML5 Up template: https://html5up.net/lens我正在使用以下 HTML5 Up 模板: https : //html5up.net/lens

... and I would like to be able to link to a specific slide in the slide show from an external site. ...我希望能够从外部站点链接到幻灯片放映中的特定幻灯片。

How can I add deep links to the template?如何向模板添加深层链接?

You need to switch slides by javascript, that's the way the template is built.您需要通过javascript切换幻灯片,这就是模板的构建方式。

First off, the link you have has a iframe to https://html5up.net/uploads/demos/lens/ - looking at the code there you will find the library main.js that declares a main object.首先,您拥有的链接有一个指向https://html5up.net/uploads/demos/lens/的 iframe - 查看那里的代码,您将找到声明main对象的库main.js。

Using this main you can switch slides as follows:使用此main您可以按如下方式切换幻灯片:

main.switchTo(number);

Where number is the number of the slide.其中 number 是幻灯片的编号。

Now, what you need is to handle the url parameters in javascript and use them to invoke that.现在,您需要在 javascript 中处理 url 参数并使用它们来调用它。 In order to do so, take code from How can I get query string values in JavaScript?为此,请从如何在 JavaScript 中获取查询字符串值中获取代码 and run it as soon as the page loads.并在页面加载后立即运行它。

It looks like this:它看起来像这样:

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

$(document).ready(function(){
   var slideNumber = getParameterByName('slideNumber');
   if(slideNumber !== null)
   {
       main.switchTo(parseInt(slideNumber, 10));
   }
});

And then you should be able to trigger that code by adding query string of the form ?slideNumber=1 to the url.然后您应该能够通过将?slideNumber=1形式的查询字符串添加到 url 来触发该代码。

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

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