From the Super Mario Wiki, the Mario encyclopedia
As suggested by their name, ON/OFF Barrels act similar to light switches. They are either found on the ground or in mid-air. By default, every ON/OFF Barrel has the white text 'OFF' painted on them. If Donkey Kong and Diddy Kong touch an ON/OFF Barrel, all of them change to 'ON'. This causes the level to illuminate for a few seconds, allowing the Kongs to see the path and the enemies ahead. ON/OFF Barrels are similar to the Stop & Go Barrels from Stop & Go Station.
In the Game Boy Color remake, Loopy Lights is not as dark while the ON/OFF Barrels are turned off. In the Game Boy Advance remake, the level has a maroon tint while they are off, making it even less dark.
In Donkey Kong Land 2 during the level Glimmer's Galleon, there is a type of barrel similar to the ON/OFF Barrels. They have a small light bulb icon displayed on them, and when Diddy and Dixie touch one of these barrels, they temporarily brighten up the level.