Deeplinking Within Flexslider (or any slider)

丶灬走出姿态 提交于 2020-01-03 01:55:08

问题


I want to add deeplinking into flexslider..

The ability to click on a specific link:

<a href="#contact">whatever text..</a>

id, and it will take me to the specific slider li. Is this possible? e.g.

<ul>
    <li id="title">...</li>
    <li id="title2">...</li>
    <li id="title3">...</li>
    <li id="contact">...</li>
</ul>

-Neil


回答1:


Use the JavaScript's window.location.hash. Use any of these:

  1. var hash = $(this).attr('href').split('#')[1];
  2. var hash = $(this).attr('href').replace(/^.*?#/,'');
  3. var hash = $(this).attr('href').substr(test.indexOf('#')+1);
  4. var hash = $(this).attr('href').match(/#(.*$)/)[1];

Use this code then:

var hash = window.location.hash;
$("#" + hash).show();

This will show the particular div from the given URL. You can take this code as a reference:

JavaScript

$(document).ready(function(){
    var hash = window.location.hash;
    $("#hash").html(hash);
    $("div").removeClass("selected");
    $(hash).addClass("selected");
});

HTML

<a href="#one">One</a>
<a href="#two">Two</a>

<div id="one">One</div>
<div id="two">Two</div>
<div id="hash"></div>

CSS

.selected {background: #ff0;}

Fiddle: http://jsfiddle.net/praveenscience/F2whf/



来源:https://stackoverflow.com/questions/19561800/deeplinking-within-flexslider-or-any-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!