如何显示基于URL中的变量的图像 [英] How to display image based on variable in url

查看:62
本文介绍了如何显示基于URL中的变量的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Gallerific http://www.twospy.com/galleriffic/来显示缩略图和用户单击缩略图时的大图像.您可以在此处 http://kimmelkids.com/kimmelkids/gallery/view-gallery上查看它/

I am using gallerific http://www.twospy.com/galleriffic/ to display thumbnails and large images when a user clicks a thumbnail. You can see it in action here http://kimmelkids.com/kimmelkids/gallery/view-gallery/

我的问题是我知道jquery可以从URL中获取变量,这就是如何改变图片.但是当我输入网址 http://kimmelkids.com/kimmelkids/gallery/view -gallery/#leaf 到地址栏中,它应该转到图库中的图像,但不是.

My question is I know jquery can grab variables from the url and that is how gallerific changes images. But when I put in the url http://kimmelkids.com/kimmelkids/gallery/view-gallery/#leaf into the address bar it should go to the image in the gallery but it doesn't.

有什么方法可以根据输入到地址栏中的url来获取图片吗?

Is there any way to have gallerific pull up the image based on the url enter into the address bar?

推荐答案

是的,window.location.hash方便地在URL末尾提供了井号.您可以尝试以下方法:

Yes, window.location.hash conveniently gives us the hashtag at the end of the URL. You could try this:

$(document).ready(function() {
  // Which anchor is being used?
  switch(window.location.hash) {
     case "#leaf":
       // do something to show leaf
     break;
     case "#carrot":
       // do something to show carrot
     break;
  }
});

..或者,如果您愿意,可以为每个图像分配一个特定的锚点(例如通过id ='leaf'等),并使用jQuery来处理ID为window.location.hash的任何图像.

..or if you want you could assign a specific anchor to each image (like through id='leaf' or something) and use some jQuery to just act on any image with the ID of window.location.hash.

这篇关于如何显示基于URL中的变量的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆