javascript - JQuery image swap inside a div -
i'm trying achieve similar this.
the image coming feed url, i'm unsure of how prevent each of them opening in new window, here have far:
javascript:
jquery/1.3.2/jquery.min.js
<script type="text/javascript"> jquery(function($){ $('#more-views a').click(function(){ $('#main-image img').fadeout('slow').delay(2000).remove(); //$('#main-image').append('<img src="' + $(this).attr('href') + '" alt="" style="display:none;" />'); $('#main-image').append('<img src="' + $(this).attr('data') + '" alt="" style="display:none;" />'); $('#main-image img').fadein('slow'); return false; }); }); </script> html
<div id="more-views"> <a data="http://www.domain.com/image1.jpg"> 1 day</a> <a data="http://www.domain.com/image2.jpg"> 5 days</a> <a data="http://www.domain.com/image3.jpg"> 1 month</a> </div> <div id="main-image"> <img src="http://www.domain.com/image1.jpg" alt="1d" /> </div> please help! thanks!
try adding line javascript test , see if add paragraph tag. if does, may instead have problem the urls images instead of code here.
jquery(function($){ $('#more-views a').click(function(){ $('#main-image p').fadeout('slow').delay(2000).remove(); //-------v add line testing $('#main-image').append('<p>' + $(this).attr('href') + '</p>); $('#main-image').append('<img src="' + $(this).attr('href') + '" alt="" style="display:none;" />'); $('#main-image p').fadein('slow'); return false; }); }); ==less old==
ok, think understand problem now. instead of having <a> tags have href attribute, use data attribute instead.
so anchor tag should this:
<a data='domain.com/image1.jpg'>image1</a> and need replace 2 of javascript lines:
$('#main-image').append('<img src="' + $(this).attr('href') + '" alt="" style="display:none;" />'); becomes:
$('#default-market-chart').append('<img src="' + $(this).attr('data') + '" alt="" style="display:none;" />'); and, have replace instances of #main-image in javascript #default-market-chart, since don't seem have element , id of main-image
==old==
try replacing < , > < , >, web page treat string giving html tag, , not string.
Comments
Post a Comment