JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 6th, 2012, 06:26 AM
mbreezy mbreezy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 110 mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 21 h 58 m 49 sec
Reputation Power: 23
jQuery - Animate a span, hide it, change text, show it, animate it back out

Explained it in the subject.

I've a span element with some text in it, when that element is clicked I want it to slide out (left side as an anchor, right side compressing to the left, I've accomplished this thus far with float:left), change the text and then slide back out showing the new text.

So far I've been able to get the span to slide out and hide, but beyond that, nothing. Oh, and I can get the text to change with innerHTML but that's it.

Any ideas?

I've a span...

Code:
<span id="test">some text here</span>



I've some Jquery...

Code:
    $("#test").click(function () {
	  $(this).animate({width: "0"}, 1000, function(){
		$(this).hide();
	});
   	  document.getElementById("test").innerHTML = "different text than original";		
	  $(this).show();
	  $(this).animate({width: "100"}, 1000);
    });

Reply With Quote
  #2  
Old October 6th, 2012, 07:59 AM
YellowBricks YellowBricks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Location: Hannover, Germany
Posts: 11 YellowBricks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m 33 sec
Reputation Power: 0
try this:
JavaScript Code:
Original - JavaScript Code
  1. $("#test").click(function () {
  2.     var $this = $(this);
  3.     $this.animate({width: "0"}, 1000, function() {
  4.         $this
  5.           .hide()
  6.           .text("different text than original")
  7.           .show()
  8.           .animate({width: "100"}, 1000);
  9.     });
  10. });

Reply With Quote
  #3  
Old October 7th, 2012, 06:23 AM
mbreezy mbreezy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 110 mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 21 h 58 m 49 sec
Reputation Power: 23
Thanks tons! That worked perfect!

I'm also trying something else. I've a list of items that I want to display for a few seconds, fade away (fadeto in jq), change the text to the next item in the list, do the same thing and so on. At the end of the list I'd like to start it from the beginning. Right now I'm messing with the code you posted because I think it's a good starting point.

Running into problems displaying from a list (bunch of text isn't hard) and integrating the setInterval.


Quote:
Originally Posted by YellowBricks
try this:
JavaScript Code:
Original - JavaScript Code
  1. $("#test").click(function () {
  2.     var $this = $(this);
  3.     $this.animate({width: "0"}, 1000, function() {
  4.         $this
  5.           .hide()
  6.           .text("different text than original")
  7.           .show()
  8.           .animate({width: "100"}, 1000);
  9.     });
  10. });

Reply With Quote
  #4  
Old October 7th, 2012, 09:17 AM
YellowBricks YellowBricks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Location: Hannover, Germany
Posts: 11 YellowBricks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m 33 sec
Reputation Power: 0
you mean something like this:
http://jsbin.com/inegal/1/edit

With this js:
JavaScript Code:
Original - JavaScript Code
  1. var items = ["Item 1", "Item 2", "Item 3", "Item 4"],     
  2. cur_item = 1,     
  3. ticker = $("#ticker");
  4.  
  5. ticker.text(items[0]);
  6.  
  7. setInterval(function() {     
  8.     cur_item = (cur_item+1 > items.length - 1) ? 0: cur_item+1;     
  9.     ticker.text(items[cur_item]);   
  10. }, 1500);

Reply With Quote
  #5  
Old October 7th, 2012, 02:14 PM
mbreezy mbreezy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 110 mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level)mbreezy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 21 h 58 m 49 sec
Reputation Power: 23
Almost exactly what I'm looking for, I was just seeing it it was possible to do with Jquery. I'm working on getting that code you showed me to fade with each one.

Quote:
Originally Posted by YellowBricks
you mean something like this:
http://jsbin.com/inegal/1/edit

With this js:
JavaScript Code:
Original - JavaScript Code
  1. var items = ["Item 1", "Item 2", "Item 3", "Item 4"],     
  2. cur_item = 1,     
  3. ticker = $("#ticker");
  4.  
  5. ticker.text(items[0]);
  6.  
  7. setInterval(function() {     
  8.     cur_item = (cur_item+1 > items.length - 1) ? 0: cur_item+1;     
  9.     ticker.text(items[cur_item]);   
  10. }, 1500);

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > jQuery - Animate a span, hide it, change text, show it, animate it back out

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap