Reposition picture "overlays" additional HTML components

I am struggling with rotating an image by clicking on a button as the image overlaps the buttons. Can anyone provide guidance on how to achieve this without overlapping?

For reference, here is my code and an example: here (http://jsfiddle.net/jj03b17n/5/).

Current situation:

https://i.sstatic.net/lIiWB.png

Desired outcome:

https://i.sstatic.net/LuEkl.png

JavaScript code for rotation:

        $(optionsPreview.rotateRightBt).unbind("click").click(function () {
                var deg = $(optionsPreview.img).data('rotate') || 0;

                if (deg == 0) deg = 90;
                else deg = deg + 90 == 360 ? 0 : deg + 90

                $(optionsPreview.img).data('rotate', deg);

                var rotate = 'rotate(' + deg + 'deg)';
                $(optionsPreview.img).css({
                    '-webkit-transform': rotate,
                    '-moz-transform': rotate,
                    '-o-transform': rotate,
                    '-ms-transform': rotate,
                    'transform': rotate
                });
                return false;
            });

Answer №1

To adjust the margin-top of the .tdBarPreview element in jQuery, you can dynamically calculate the size of the image. For instance, if the image is not zoomed in, you can use the following code snippet. However, if the image is zoomed, you would need to retrieve its dimensions and update the margin-top property accordingly.

.tdBarPreview
{ 
    display:block;
    margin-top:20px;
}

Answer №2

Hello @Ninita! When you use CSS to rotate an element, the pivot point of the rotation is set at the center of the element. In your jsfiddle code (http://jsfiddle.net/bjLqztdw/), you can see that the rotation pivot is at the center where the yellow 'O' is located.

If you want to change the pivot's position and have the rotation vary accordingly, you need to adjust the "-webkit-transform-origin" style.

I've updated your JSFiddle link here: (http://jsfiddle.net/bjLqztdw/1/). Feel free to experiment with changing the pivot point.

$(optionsPreview.img).css({
 '-webkit-transform': rotate,
 '-moz-transform': rotate,
 '-o-transform': rotate,
 '-ms-transform': rotate,
 'transform': rotate,
 '-webkit-transform-origin': '90% 30%',
});

Reference:

Answer №3

Problem resolved! By utilizing JavaScript, I was able to dynamically adjust the height of the image container based on its rotation. Essentially, when the image is in a vertical position, the height of the container is changed to match the width of the image. This can be seen in action through this example on JSFiddle:

$(optionsPreview.rotateRightBt).unbind("click").click(function () {
    var deg = $(optionsPreview.img).data('rotate') || 0;
    
    if (deg == 0) deg = 90;
    else deg = deg + 90 == 360 ? 0 : deg + 90

    $(optionsPreview.img).data('rotate', deg);

    var rotate = 'rotate(' + deg + 'deg)';
    $(optionsPreview.img).css({
        '-webkit-transform': rotate,
        '-moz-transform': rotate,
        '-o-transform': rotate,
        '-ms-transform': rotate,
        'transform': rotate
    });

    if (deg == 90 || deg == 270) {
        var width = $(optionsPreview.img).width();
        $($(optionsPreview.img).parent()).css("height", width + "px");
    }
    else
        $($(optionsPreview.img).parent()).css("height", "auto");

    return false;
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Where should AJAX-related content be placed within a hyperlink?

When needing a link to contain information for an AJAX call, where is the correct place to include the info? I have typically placed it in the rel attribute, but after reviewing the documentation for rel, it appears that this may not be the right location ...

Is there a way to retrieve data from three different Bookshelf.js models in a single query?

Three tables are in my database: User, UserDrink, and VenueDrink Here is a preview of the sample data: User id | name | gender | -------------------- 1 | John | male | 2 | Jane | female | UserDrink id | count | user_id | venue_drink_id 1 | 3 | ...

Setting the width of a wizard modal to auto

I am facing an issue with my modal wizard. The width of the first modal is perfect, but when I navigate to the second and third modals by pressing next, they automatically take on a fixed width size that I need to modify. I have tried declaring the width ...

Updating with Ajax is functional for radios and checkboxes, however it does not work for buttons

When a button is clicked, I want the form to process and update accordingly. HTML: <input type="button" value="5.00" name="updatefield" id="updatefield" class="chooseit"> I have also tried: <button name="updatefield" id="updatefield" class="ch ...

Continuous loop of Vue countdown timer

Hey there! I'm currently working on implementing a countdown timer, but I keep encountering a console error that says 'You may have an infinite update loop in a component render function.' It seems like something needs to be adjusted. expor ...

The art of bringing a pseudo class to life through animation

Seeking assistance with achieving a unique effect on click event. I have set up a slanted or razor-blade style div using a parent div element and a pseudo-element :after (as shown below). My goal is to change the skew angle when the user clicks on the pare ...

When using AJAX, make sure it doesn't overwrite the global variable for JQUERY

$.each(data, function (index, info) { var a = info.notes; var b = info.permission; //var c = null; var c = null; $.ajax({ url: "asse ...

Show a preloader using Jquery after all div elements have been fetched

My goal is to have a preloader displayed in a div, and once another div has finished loading its content, I want the preloader to disappear. Here is an example: <div id="container"> <div id="preloader"> Loading.... </div> ...

Converting lengthy timestamp for year extraction in TypeScript

I am facing a challenge with extracting the year from a date of birth value stored as a long in an object retrieved from the backend. I am using Angular 4 (TypeScript) for the frontend and I would like to convert this long value into a Date object in order ...

Functionality of the Parameters Object

As I transition from using the params hash in Rails to learning Node/Express, I find myself confused about how it all works. The Express.js documentation provides some insight: 'This property is an array containing properties mapped to the named rout ...

The date entered in the input field should also appear in all other textboxes on the

I currently have 2 tables set up on my page. In the first table, there is a textbox (txt1) that includes a date picker. The second table contains 5 similar textboxes (txt2, txt3, txt4, txt5, txt6) also with date pickers. My requirement is as follows: Ini ...

Using Slick Slider and Bootstrap CSS to display text on top of images

Currently, I am utilizing the slick slider from and I want to overlay text on top of the image. I tried using bootstrap carousel-caption, which works well with any image. However, with slick slider, it seems like the text is not at the highest level as I ...

How can one utilize a second drop-down list in asp.net to alter the selected index and visibility of a drop-down list?

I am working on an asp.net application that includes a drop down list with the following structure: <asp:DropDownList runat="server" ID="ddlChanges" CssClass="selectstyle" onchange="javascript:ddlChangesChanged();"> <asp:ListItem Text="-- Select ...

"The function you are attempting to call is not defined within the HTMLButtonElement.onclick

How do I trigger the DeleteRow and EditRow functions when clicking on the Delete Button and Edit Button? <button style="margin-right: 5px;" type='button' onclick='return EditRow(@i)' id='@editrow' class='btn btn-prima ...

Loading the Facebook JavaScript SDK asynchronously using React and Redux

I have a process that involves loading a JavaScript SDK, which looks like this: class Facebook{ constructor(){ window.fbAsyncInit = () => { FB.init({ appId : 'myappID', ...

AdjustIframeHeightOnLoad is undefined. Please define it before use

I've noticed that a few of my website pages are loading very slowly. After checking Google inspect (console), it seems like the issue is caused by this error: Uncaught ReferenceError: AdjustIframeHeightOnLoad is not defined. This specific piece of co ...

Explore the capabilities of Chart JS integration using Python Selenium

I've been attempting to click the buttons on this Chart JS located on the webpage . Despite trying by xpath, full xpath, and JS path, I have not been successful. An example of my attempt to press the "All" button can be seen below: https://i.sstatic.n ...

What is the best way to populate a select input field with options using JavaScript?

When I am loading an HTML table, there is a select input field that needs to display some options. Immediately after constructing the HTML table row, I invoke a function to populate this input field using its class. Below is the relevant HTML snippet and ...

Guide on configuring Angular validation to trigger on blur events and form submission

Validation in Angular is currently set to update on model change, but this method can be unfriendly for user interface as it displays errors upon keyup. An optimal solution would involve displaying error messages on blur and also on form submission. After ...

Is it possible to eliminate the table borders and incorporate different colors for every other row?

Eliminating the table borders and applying color to alternate rows. Check out my code snippet: https://stackblitz.com/angular/dnbermjydavk?file=app%2Ftable-overview-example.ts. ...