How to show a advert depending on screen size - google-dfp

I have a page with a banner advert that will shrink/grow depending on screen size or if it's desktop or mobile.
The banner will be displayed with in one div.
The adverts are in three different advert ID's that each have their own size:
Example:
ad-1 is 1220x350
ad-2 is 650x190
ad-3 is 300x250
How do I make the correct advert display in a div depending on the div size?

You could use sizeMapping to dispatch your sizes based on the viewport size.
First : define the sizeMapping
var mapping = googletag.sizeMapping()
.addSize([1024, 768], [1220, 350])
.addSize([980, 690], [650, 190])
.addSize([0, 0], [300, 250])
.build();
Usage : addSize([screenWidth, screenHeight], [width,height])
Second : add the mapping to your slot definition
var slot = googletag.defineSlot('/adUnitPath/', [[1220, 350], [650, 190], [300, 250]], 'yourTargetId')
.defineSizeMapping(mapping)
.addService(googletag.pubads());
Full documentation here and here

Related

Increase element opacity but accounting for the size of the element and position of it's bottom relative to "scrollTop"

I found a great example for this approach and it works fairly well but it starts changing the opacity when the TOP of the element scrolls off the page. Unfortunately with a larger element the visibility (opacity decrease) starts way too soon. I'm trying to figure out how to start lowering the opacity when the bottom of the element is in near proximity to the top of the top of the screen so that all elements start fading at the same time in relationship to their bottom (not their top).
Any ideas on how to accommodate that with this code? I like this code in terms of being able to control speed of the opacity change as well. Maybe leveraging element height?
Thanks!!
<script type="text/javascript">
$(function() {
var documentEl = $(document),
fadeElem = $('.fade-scroll');
documentEl.on('scroll', function() {
var currScrollPos = documentEl.scrollTop();
fadeElem.each(function() {
var $this = $(this),
elemOffsetTop = $this.offset().top;
if (currScrollPos > elemOffsetTop) $this.css('opacity', 1 - (currScrollPos-elemOffsetTop)/200); /* this number effects speed of fade aka opacity reduction*/
});
});
});
</script>

Blank responsive banner on cellphone and tablet (sizeMapping)

I have a custom 1600x433 banner, I've created it as responsive and I'm trying to use sizeMapping, on the desktop the banner works, however, on the tablet and mobile the banner area just goes blank.
Set custom sizes in settings> sizes. The original image has exactly. 1600x433 What am I doing wrong that the banner is not responsive as I customize it?
googletag.cmd.push(function() {
var mapping = googletag.sizeMapping().
// Accepts both common mobile banner formats
addSize([320, 400], [320, 50]).
// Same width as mapping above, more available height
addSize([320, 700], [360, 100]).
// Desktop
addSize([1050, 200], [1600, 433]).build();
googletag.defineSlot('/id/sitenovo',[320, 50], 'div-gpt-ad-0').defineSizeMapping(mapping).addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
Size [320, 400] matches a viewport greater than or equal to 320, 400 pixels. Use a size [0,0

DFP Adverts - How to show adverts in different places depending on screen size

I am using Google DFP adverts and I want to change the position they are in when the site is viewed on mobile.
I have tried duplicating the advert and showing one/ hiding the other but that still shows both adverts.
Is there any way to accomplish this, please see attached image for an example of what I am after.
Well, this is kind of hard, but not impossible. I will give you even more complicated example, where not only the banner could be in different places, but could be with different sizes depending on the device.
Scenario: You have an Ad Unit called adunit1. You want to show in the content on desktop, but on top on mobile. On desktop you want to be 300x250, and on mobile you want to 320x100 or 320x50. We consider desktop everything with viewport width of 970px and mobile anything smaller (could add more cases, but let's not make it too complicated).
Step 1: Go to the Ad Unit options in DFP and add all sizes that this ad unit will display (in our scenario: 300x250, 320x100, 320x50).
Step 2: Create size mappings variable for each sub-scenario. As bellow:
var adunit1desktop = googletag.sizeMapping().addSize([970, 0], [300, 250]).addSize([0, 0], []).build();
Which means: If viewport width is more than 970 AND viewport height is more than 0, serve banner with size 300x250. If smaller, serve nothing.
Now let us make the same for the mobile version with different name of the variable:
var adunit1mobile = googletag.sizeMapping().addSize([970, 0],[]).addSize([0, 0], [[320,100],[320,50]]).build();
Which means: If viewport width is more than 970 AND viewport height is more than 0, serve nothing. If smaller serve either 320x100 OR 320x50.
We will now define the Ad Units, but will make this twice as will assign different size mapping for desktop and mobile.
For desktop:
gptAdSlots[0] = googletag.defineSlot('/XXX/adunit1', [[300, 250], [320, 100], [320, 50]], 'div-banner-desktop').defineSizeMapping(adunit1desktop).addService(googletag.pubads());
Two details to watch here: div-banner-desktop - this is the div id where we want to show the desktop banner. defineSizeMapping(adunit1desktop) - this is how we tell DFP to show this based on the size rules above (in brief: show the desktop banner, only if viewport width is at least 970px).
Now for the mobile:
gptAdSlots[1] = googletag.defineSlot('/XXX/adunit1', [[300, 250], [320, 100], [320, 50]], 'div-banner-mobile').defineSizeMapping(adunit1mobile).addService(googletag.pubads());
Pay attention to three details: div-banner-mobile, defineSizeMapping(adunit1mobile) and gptAdSlots[1] - we increased with 1 for the next slot rendering. If there are more, each should be increased by 1 as well.
Now go to your web site and put the following code where you want to display the desktop banner:
<div id="div-banner-desktop">
<script>
googletag.cmd.push(function() { googletag.display('div-banner-desktop'); });
</script>
</div>
Now place this code where you want to display the mobile banner:
<div id="div-banner-desktop">
<script>
googletag.cmd.push(function() { googletag.display('div-banner-desktop'); });
</script>
</div>
The whole code block should look something like this
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script>
var gptAdSlots = [];
googletag.cmd.push(function() {
var adunit1desktop = googletag.sizeMapping().addSize([970, 0], [300, 250]).addSize([0, 0], []).build();
var adunit1mobile = googletag.sizeMapping().addSize([970, 0],[]).addSize([0, 0], [[320,100],[320,50]]).build();
gptAdSlots[0] = googletag.defineSlot('/XXX/adunit1', [[300, 250], [320, 100], [320, 50]], 'div-banner-desktop').defineSizeMapping(adunit1desktop).addService(googletag.pubads());
gptAdSlots[1] = googletag.defineSlot('/XXX/adunit1', [[300, 250], [320, 100], [320, 50]], 'div-banner-mobile').defineSizeMapping(adunit1mobile).addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>

sap.ui.table.Table "VisibleRowCountMode.Auto" mode does not work

I'm having trouble setting the number of rows for a table to automagically fill the available estate of its encapsulating container.
According to the API, setting the visibleRowCountMode property to sap.ui.table.VisibleRowCountMode.Auto should render the table to
"[...] automatically fills the height of the surrounding container.
The visibleRowCount property is automatically changed accordingly. All
rows need the same height, otherwise the auto mode doesn't always work
as expected."
I have used the following code:
var oTable = new sap.ui.table.Table( {
rowHeight : 30,
height : "100%",
// The below property is seemingly ignored... What did I do wrong?
visibleRowCountMode : sap.ui.table.VisibleRowCountMode.Auto
});
...but as you can see in this jsbin example http://jsbin.com/vazuz/1/edit it just shows the default 10 rows, and certainly doesn't "change the visibleRowCount property accordingly" :-(
Anyone has a solution?
Thanks in advance!
=====================
EDIT: Thanks to #matz3's answer below, I was ultimately able to solve this issue.
Setting the surrounding container DIV to 100%, this seems to be ignored. Setting it to a fixed height, however, worked just fine. But what I really wanted, if a user resized the window, the number of available rows needs to be adjusted accordingly. Setting it to a fixed height is therefor not an option...
However, the trick was in some extra CSS: not only the DIV needed to be set to 100% height, also both BODY and HTML (!!) needed to have a height set to 100%:
html, body {
height: 100%
}
div#uiArea {
height: 100%
}
Now, the table spans the full height of the available viewport, and resizing the window adjusts the table rather nicely. See the final working solution here: http://jsbin.com/bosusuya/3/edit
Matz3, thanks for your help!
CSS hacks is a dirty way. In my application I use to bind visibleRowCount to Array.length
For example, if you have model with this data:
[{firstName: 'John', lastName: 'Smith',
{firstName: 'David', lastName: 'Ericsson'}]
You can bind to Array property length like this:
var oTable = new sap.ui.table.Table({
visibleRowCount : '{/length}'
})
[...] automatically fills the height of the surrounding container [...]
Your surrounding container is the view, so you have to set the height of it also to a value (e.g. 100%)
this.setHeight("100%");
And your view will be set into the uiArea-div, so this one also needs a height (e.g. 500px)
<div id="uiArea" style="height:500px"></div>
With these changes it now works as expected
I'm with the same issue. I "resolve" that in this manner. This is not perfect, but it's better than UI5 resizing...
  _resizeTableRow: function () {
var oTable = this.getView().byId("referenceTabId");
var sTop = $('#' + oTable.getId()).offset().top;
var sHeight = $(document).height();
//if there a row, you can take the row Height
//var iRowHeight = $(oTable.getAggregation("rows")[0].getDomRef()).height();
var iRowHeight = 40;
var iRows = Math.trunc((sHeight - sTop ) / iRowHeight);
oTable.setVisibleRowCount(iRows);
   },
Other option is to put the Table in sap.ui.layout.Splitter:

Make Firefox Panel fit content

I'm manually porting an extension I wrote in Chrome over to Firefox. I'm attaching a panel to a widget, and setting the content of that panel as an HTML file. How can I make the panel shrink and grow with the content? There's a lot of unsightly scroll bars and grey background right now.
var data = require("self").data;
var text_entry = require("panel").Panel({
width: 320,
height: 181,
contentURL: data.url("text-entry.html"),
contentScriptFile: data.url("get-text.js")
});
require("widget").Widget({
label: "Text entry",
id: "text-entry",
contentURL: "http://www.mozilla.org/favicon.ico",
panel: text_entry
});
Not setting the height property of the panel makes it quite tall.
You might want to check out this example that resizes the panel based on the document loaded. If you want to resize based on changes to the content size, at least on initial load:
https://builder.addons.mozilla.org/package/150225/latest/
( sorry for the delay in respinding, been afk travelling )