Variable in jquery animate command

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
musicscore
Power Poster
Power Poster
Posts: 495
Joined: Wed Jan 25, 2006 11:53 am

Variable in jquery animate command

Post by musicscore »

Hey There,

I fighting with a jquery script and I'm losing.
So I need some help.

What I want is to create a variable containing css setting
Then I want to use this variable in a jquery animate command:

I searched the internet and tried, tried and tried but .... without any luck.

This is what I tought would work (but isn't).

In smarty template I set a variable (stylecss_start) :

Code: Select all

{assign var="stylecss_start" value='opacity: 1'}
Then I move this variable to jquery and check if it is set :

Code: Select all

var start_stylecss = {/literal}"{$stylecss_start}"{literal};
alert(start_stylecss);
The alert shows the "opacity: 1" so the variable is set.

Then I want to use this variable in the jquery animation :

Code: Select all

$(".myPopup").animate( start_stylecss );
I tried the following (I found on the internet):

Code: Select all

$(".myPopup").animate( { start_stylecss } );
$(".myPopup").animate( { + start_stylecss + } );
$(".myPopup").animate( "start_stylecss" );
Nothing seems to work.

The jquery is part of the tpl file so no extra jquery file to import.

Without the variable it is working

Code: Select all

$(".myPopup").animate( {opacity: 1});
Please advise/help.

???
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: Variable in jquery animate command

Post by Jo Morg »

Take a closer look at what is the final code you need to be rendered by Smarty:

Code: Select all

$(".myPopup").animate( {opacity: 1});
The {opacity: 1} is a Javascrip object and it needs the "{" and "}" as part of the object structure declaration... additionally, a Smarty variable needs to be rendered by using "{" and "}" so all that seems to be missing... this should work (didn't test it though):

Code: Select all

$(".myPopup").animate( { {$start_stylecss} } );
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1799
Joined: Wed Feb 25, 2009 4:25 am

Re: Variable in jquery animate command

Post by DIGI3 »

Almost, since you have it as a js variable you should be able to do:

Code: Select all

$(".myPopup").animate( { start_stylecss } );
although jomorg's answer should work if you allow Smarty in the code (ie get rid of all the {literal} stuff and just use spaces around curly braces that aren't Smarty.
Not getting the answer you need? CMSMS support options
Post Reply

Return to “Developers Discussion”