compress a website to display advertisement

Here is a JSFiddle link I would like to share with you:

I am currently working on squeezing the webpage to display an ad on the right side.

http://jsfiddle.net/5o6ghf9d/1/

It works well on desktop browsers, but I am facing issues with iPad Safari/Chrome browsers as the page is not getting squeezed properly.

Below are the functions that I am using to squeeze and unsqueeze the webpage:

 function squeeze_page(){
    d.body.style.paddingRight='160px';
    d.body.style.paddingLeft='160px';
    d.body.style.marginLeft='-160px';
    d.body.style.overflowX='hidden !important'; 
    is_page_squeezed=true;
 }

 function unsqueeze_page(){
   d.body.style.paddingRight='';
   d.body.style.paddingLeft='';
   d.body.style.marginLeft='';
   is_page_squeezed=false;
 }

If you have any suggestions or alternative methods to squeeze the webpage effectively, please let me know.

Answer №1

Could this be the solution you're seeking? Check it out here: JSFIDDLE

If your goal is to make the AD slide in from the right when displayed, utilizing a CSS transition similar to my illustration would be more effective.

Initially, establish a container for the content as shown in my example:

<div id="container">
    ...
    <!-- Your Content Here -->
    ...
</div>

This container encapsulates all your <p> content. By applying the following CSS:

#test {
    position:fixed;
    width:160px;
    background:blue;
    right:-160px;
    top:0px;
    bottom:0px;
    -webkit-transition: all ease-in-out 1s;
    -moz-transition: all ease-in-out 1s;
    transition: all ease-in-out 1s;
}
#test.show {
    right:0;
}

With position:fixed;, its position remains fixed within the viewport while scrolling. Setting top and bottom to 0 ensures full height coverage. The defined transition facilitates the sliding effect from right to left upon display.

A similar approach applies to the styled div container:

#container {
    margin-right:0;
    -webkit-transition: all ease-in-out 1s;
    -moz-transition: all ease-in-out 1s;
    transition: all ease-in-out 1s;
}
#container.squeezed {
    margin-right:160px;
}

This configuration gives the appearance of being compressed by the AD.

Subsequently, utilize this script for dynamically adding or removing classes from #container and #test:

window.onscroll = function () {
    if (pageYOffset > 100) {
        $("#test").addClass("show");
        $("#container").addClass("squeezed");
    } else if (pageYOffset < 100) {
        $("#test").removeClass("show");
        $("#container").removeClass("squeezed");
    }    
}

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

Error: Loop Program Encountered Unexpected Token Syntax

Every time I attempt to run this code, a syntax error (unexpected token) appears. As someone who is still learning JavaScript, I am struggling to identify the root cause of this issue. var x = 1; var example = function(){ for(var y = 0; y < ...

Retrieve or update the selected option value in a Select2 multiple dropdown

I'm currently using Select2 for multiselect on an input field. My goal is to identify which choice has been clicked, but when I inspect the event triggered upon clicking a choice ("choice-selected"), all I see is event.target.value which contains the ...

provide a hyperlink to the icon located in front of the navigation bar

I'm struggling to come up with a suitable title for this issue. What I am trying to achieve is placing a small icon in front of the navbar so that visitors can click on it and be directed to another site. Initially, I attempted to place the icon using ...

How to Ensure Center Column Maintains Visibility on Mobile Devices with Bootstrap 4

Is there a way to ensure that page content stays centered without looking too narrow when viewed on mobile devices? Specifically, in the context of a single column layout that is centered. Although the current design appears well-balanced and spaced out o ...

Grab the contents of the header while excluding specific attributes

CSS <div [@class="another class"]> <p> Different text <span> yet more text </span> </p> </div> Is there a way to create a selector in CSS to style the text inside p that is not within the child eleme ...

Having trouble getting my Leaflet map to display even after meticulously following the quick-start guide

I am experiencing an issue where the map is not displaying at all, leaving a blank space where it should be. Despite following Leaflet's quick-start guide, I have been unable to determine the cause of this problem. Here is the code that I currently h ...

Test fails in Jest - component creation test result is undefined

I am currently working on writing a Jest test to verify the creation of a component in Angular. However, when I execute the test, it returns undefined with the following message: OrderDetailsDeliveryTabComponent › should create expect(received).toBeTru ...

Differences in Spacing: Exploring Bootstrap v5.1.1 Compared to 4.0

After comparing two pages, one using Bootstrap v5.1.1 and the other with 4.0.0, I have observed differences in spacing. Bootstrap v5.1.1: .topspacer { padding-top: 70px; } .righticon { float: right; } .clear { clear: both; } a { text- ...

Ways to change content within an editable div without altering the current cursor location

In the javascript code below, I am trying to highlight characters after 255 and display them in another div with a different color. $( "#testdiv" ).keyup(function() { if($("#testdiv").text().length>255) { var text = $("#info").text() $("#te ...

Can you provide some guidance on accessing HTTP headers while using Promises to make AJAX requests?

Currently, I am working on resolving jQuery ajax requests using bluebird.js and I have found it quite challenging to access the HTTP headers of the request. Here is a snippet of the code I am working with: Promise.resolve($.get(...)).then(function(data){ ...

What is the reason for not displaying the various li elements on my webpage?

Here is the code snippet export default function DisplaySearchResults({ results }) { var arr = Object.entries(results) console.log(arr) return ( <div> Here are the search results : <ol> {arr.map((va ...

Javascript's ReferenceError occasionally acts inconsistently when using Firefox's scratchpad

While delving into the world of Javascript for learning purposes, I encountered an unexpected behavior. Let's explore this scenario: function hello(name) { let greet = 'Hello ' alert(greet + name) } hello('world') alert(gree ...

What is the best practice for using templates in a constructor versus connectedCallback?

Should I apply template in the constructor or connectedCallback of a custom element? In my experience, when I apply it in connectedCallback, sometimes attributeChangedCallback is called before and I can't query for elements. export class TestElement ...

What is the best way to retrieve the scope of ng-repeat from another directive located on the same element as ng-repeat?

Is it possible to access a property from the ng-repeat scope in another directive within the same element as the ng-repeat directive? For instance, I would like to be able to use the child.class property in this scenario: <div ng-class="{{ child.class ...

Error in canvas-sketch: "THREE.ParametricGeometry has been relocated to /examples/jsm/geometries/ParametricGeometry.js"

I recently started using canvas-sketch to create some exciting Three.js content. For my Three.js template, I utilized the following command: canvas-sketch --new --template=three --open The version that got installed is 1.11.14 canvas-sketch -v When atte ...

Unable to pass the jQuery value - troubleshooting tips for Laravel

JavaScript Issue return response()->json([ 'category' => $category, 'editRoute' => $artistCategoriesEditRoute ]); AJAX Response category Object { id: 1, title: "tt", parent_id: 0, … } id ...

Disable a tab or menu item if the bean's boolean value is 'false'

I designed a home page with various menu/tab options that redirect the user when clicked, but only if they have access to that specific item. If access is not granted, the menu item becomes unclickable. While this functionality works, I am interested in en ...

Oops! An error occurred: Uncaught promise rejection - invalid link found for ProductListComponent

I am currently in the process of learning Angular and Ionic, but I am feeling a bit confused as to where my mistake is. I have looked at other questions, but I still can't seem to figure it out. Can anyone provide some assistance? Perhaps someone has ...

Is it time to shake up the location of your Toastr

Recently, I've been working on implementing Toastr from this GitHub repository. While I am able to receive alerts and toasts as intended, I'm running into issues when trying to apply custom options. It seems to only stick to the default settings ...

Error: SyntaxError - Unexpected token 'if' found. Additionally, ReferenceError - berechnung is not defined

I keep encountering two error messages and I'm not sure where the issue lies: Uncaught SyntaxError: Unexpected token 'if' Uncaught ReferenceError: berechnung is not defined Any idea what might be causing this problem? I've reviewed t ...