$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Zoom specific element on webcontent (HTML,CSS,JavaScript) - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Zoom specific element on webcontent (HTML,CSS,JavaScript) - Stack Overflow

matteradmin24PV0评论

I want to zoom only a specific element of my website (a certain div), if a user zooms the website on a mobile device. The following picture shows my idea:

As you can see, the test is zoomed but the top div stays the same size; only the div that contains test is zoomed / scaled.

Could someone give me some tips on how to achieve this? I really don't know where to start.

UPDATE: /. if I would zoom in on this page, it would scale both elements. I want to adjust just the content element when zooming. One way I can think of to achieve this is to retrieve the user-input and use javascript to adjust the div's width but this is contradictory with the usual behavior.

Pseudo-code:

container.mousemove {
   content.changeWidth();..
}

I want to zoom only a specific element of my website (a certain div), if a user zooms the website on a mobile device. The following picture shows my idea:

As you can see, the test is zoomed but the top div stays the same size; only the div that contains test is zoomed / scaled.

Could someone give me some tips on how to achieve this? I really don't know where to start.

UPDATE: http://jsfiddle.net/WyqSf/. if I would zoom in on this page, it would scale both elements. I want to adjust just the content element when zooming. One way I can think of to achieve this is to retrieve the user-input and use javascript to adjust the div's width but this is contradictory with the usual behavior.

Pseudo-code:

container.mousemove {
   content.changeWidth();..
}
Share Improve this question edited Feb 20, 2018 at 15:40 Basj 46.3k109 gold badges450 silver badges795 bronze badges asked Jul 22, 2013 at 7:55 BramBram 4,6136 gold badges31 silver badges41 bronze badges 5
  • Paste some of you code or a fiddle. Without code we cant help much.Use CSS. – AnaMaria Commented Jul 22, 2013 at 8:03
  • for starters have at look at this stackoverflow.com/questions/4049342/… – Sunny Patel Commented Jul 22, 2013 at 8:04
  • 1 @sunny. He is not looking to zoom into the entire site. he's looking to zoom only the text part... – AnaMaria Commented Jul 22, 2013 at 9:03
  • I updated my post. It includes a basic fiddle now ;) Thanks for helping in advance. – Bram Commented Jul 22, 2013 at 9:42
  • you can try add event listner and prevent defaults (user can't zoom page) and after that zoom a specific element – David Commented Jul 28, 2013 at 9:01
Add a comment  | 

2 Answers 2

Reset to default 23 +50

In order to do this, you would need to fix the user's viewport so that they cannot pinch zoom the page, and then use a touch events library like Hammer.js to attach a callback to the pinch zoom gesture that appropriately resizes the element on the page you'd like to scale.

viewport fixing happens in the head element of your html:

<meta name="viewport" content="width=device-width, maximum-scale=1.0">

you would use hammer.js to detect a "pinch zoom" gesture, and the library gives you a very detailed event.gesture object which you can use to detect how much/how fast the user is zooming.

The change in distance between the 2 touch points while pinching is represented by event.gesture.scale (see hammer documentation), if the scale increases, increase the text accordingly ... if it decreases decrease the text-size. Use Math:

$('body').hammer().on("pinch", function(event) {
    console.log(event.gesture.scale);
    // do math...
});

I imagine you get the idea...

You could use the Zoomooz plugin. Inside the documentation, check the Zooming inside a container section -- this is what you may need:

<div class="zoomViewport">
    <div class="zoomContainer">
        <div class="zoomTarget">Target 1</div>
        <div class="zoomTarget">Target 2</div>
    </div>
</div>

Check the JS Fiddle

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far