...">

Jquery extract values ​​from css

How to extract a style property

<div id="clipProperty" style="clip: rect(0px 281px 647px 0px);"></div>

      

and add it to # getClipVaalues ​​with 30 subtracted from the second value 281, so it says clip: rect (0px 251px 647px 0px)?

 <div id="getClipValues"></div>

      

This is my js code

var clipProperty = $('#clipProperty').attr('style');
$('#getClipValues').attr('style', clipProperty);

      

The clipProperty property is not constant, but changes regularly. But I always need to subtract 30 from the second value.

+3


source to share


2 answers


This would do it:



var re = /rect\((\d+)px (\d+)px (\d+)px (\d+)px\)/;
var oldClip = $('#clipProperty').css('clip');
var newClipVal = oldClip.replace(re, "$2");
$('#getClipValues').css('clip','rect(0px '+(newClipVal-30)+'px 647px 0px)');

      

+3


source


You are looking for something like this:

var clip = $('#clipProperty').attr('style'); 

var clip2 = $('#getClipValues').css('clip', 'rect(0px 231px 647px 0px');

      



I did a little jsFiddle with it to get the result: http://jsfiddle.net/jtu5y1te/1/

0


source







All Articles