Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-17 13:24:13

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

[Solved] jQuery images change

Hi folks.

in order to optimize loading I’m trying to change on the fly images resources for small screens.

Here is my jQuery code:

var $window = $(window);

function checkWidth() {
	var windowsize = $window.width();
	if (windowsize < 767) {
		$('figure a img').each(function(){
			$(this).attr('scr').replace(/(.*[0-9]+)\.([a-z]{3})/gi, '$1t.$2');
		});
	}
}
// Execute on load
checkWidth();
// Bind event listener
$(window).resize(checkWidth);

Unfortunately, I’ve got no results.
Could you tell me where I’m wrong?

Thanks in advance.

Last edited by Pat64 (2012-09-18 09:08:18)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#2 2012-09-17 13:39:12

etc
Developer
Registered: 2010-11-11
Posts: 5,057
Website GitHub

Re: [Solved] jQuery images change

Hi Patrick,

what is attr('scr'), did you mean src?

Offline

#3 2012-09-17 13:48:22

etc
Developer
Registered: 2010-11-11
Posts: 5,057
Website GitHub

Re: [Solved] jQuery images change

Anyway, IMO body is loaded after img, so it will be too late to change their src. You could try adi_mobile, eventually jointly with etc_query to do it server side.

Offline

#4 2012-09-17 14:40:52

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

Re: [Solved] jQuery images change

@etc: You’re right, man!

@all: Folks, It seems obvious I’m suffering of dyslexia…

I’m using lam_image & adi_mobile plugins in conjunction: these two make the trick :)

Last edited by Pat64 (2012-09-18 09:07:58)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

Board footer

Powered by FluxBB