KevinBatdorf / liquidslider

A Responsive jQuery Content Slider
161 stars 62 forks source link

How to link to slides from extern per #id #166

Open Shiuyin opened 8 years ago

Shiuyin commented 8 years ago

I really need to link to a page that contains a slider and let the slider open at a specific slide. I googled about an hour and found pieces of information that it should be possible. I got it working to open from extern by #name, as the name is defined by .title. This is the code i am using:

$(".liquid-slider").liquidSlider({ onload: function () { this.alignNavigation(); }, continuous: false, slideEaseFunction: "easeInOutCubic", hashLinking: true });

I just don't know how to make it not take the names as the hashtags, but the ids. Can someone explaint that to me? Thanks :)

KevinBatdorf commented 8 years ago

You could try something like this:

// Grab the hash
var hash = parseInt(window.location.hash.substring(1));

// If it's a number, set the first panel. Otherwise default to 1.
// You might want to add some further validation
var first = (typeof hash === "number") ? hash : 1;

$(".liquid-slider").liquidSlider({ 
  onload: function () { 
    this.alignNavigation(); 
  },
  firstPanelToLoad:first,
  continuous: false, 
  slideEaseFunction: "easeInOutCubic", 
  hashLinking: true 
});
Shiuyin commented 8 years ago

Works like a charm. Thanks a lot, wouldn't have thought of that.

Also: How do I actually add new slides to slider after it has been build()? I looked into your source code and all i can see is manually caling build() again on the slider, after adding the

with the new content and destroying the old slider object. Is there a better way? :)

KevinBatdorf commented 8 years ago

Yeah unfortunately there isn't a clean way to do it. You might be able to add it to the array and then call some of the build functions separately but I'm not sure if it will work.